Commit a29eb08f authored by Serhiy Storchaka's avatar Serhiy Storchaka

Fixed possible leaks in ElementTree parser.

parent d6a69d8c
...@@ -2935,8 +2935,10 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in, ...@@ -2935,8 +2935,10 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
/* attributes */ /* attributes */
if (attrib_in[0]) { if (attrib_in[0]) {
attrib = PyDict_New(); attrib = PyDict_New();
if (!attrib) if (!attrib) {
Py_DECREF(tag);
return; return;
}
while (attrib_in[0] && attrib_in[1]) { while (attrib_in[0] && attrib_in[1]) {
PyObject* key = makeuniversal(self, attrib_in[0]); PyObject* key = makeuniversal(self, attrib_in[0]);
PyObject* value = PyUnicode_DecodeUTF8(attrib_in[1], strlen(attrib_in[1]), "strict"); PyObject* value = PyUnicode_DecodeUTF8(attrib_in[1], strlen(attrib_in[1]), "strict");
...@@ -2944,6 +2946,7 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in, ...@@ -2944,6 +2946,7 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
Py_XDECREF(value); Py_XDECREF(value);
Py_XDECREF(key); Py_XDECREF(key);
Py_DECREF(attrib); Py_DECREF(attrib);
Py_DECREF(tag);
return; return;
} }
ok = PyDict_SetItem(attrib, key, value); ok = PyDict_SetItem(attrib, key, value);
...@@ -2951,6 +2954,7 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in, ...@@ -2951,6 +2954,7 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
Py_DECREF(key); Py_DECREF(key);
if (ok < 0) { if (ok < 0) {
Py_DECREF(attrib); Py_DECREF(attrib);
Py_DECREF(tag);
return; return;
} }
attrib_in += 2; attrib_in += 2;
...@@ -2958,9 +2962,11 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in, ...@@ -2958,9 +2962,11 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
} else { } else {
/* Pass an empty dictionary on */ /* Pass an empty dictionary on */
attrib = PyDict_New(); attrib = PyDict_New();
if (!attrib) if (!attrib) {
Py_DECREF(tag);
return; return;
} }
}
if (TreeBuilder_CheckExact(self->target)) { if (TreeBuilder_CheckExact(self->target)) {
/* shortcut */ /* shortcut */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment