Commit 33ea2977 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Fixed possible leaks in ElementTree parser.

parent 6b93ca6a
...@@ -2227,8 +2227,10 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in, ...@@ -2227,8 +2227,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 = makestring(attrib_in[1], strlen(attrib_in[1])); PyObject* value = makestring(attrib_in[1], strlen(attrib_in[1]));
...@@ -2236,6 +2238,7 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in, ...@@ -2236,6 +2238,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);
...@@ -2243,6 +2246,7 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in, ...@@ -2243,6 +2246,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;
...@@ -2260,8 +2264,10 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in, ...@@ -2260,8 +2264,10 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
if (attrib == Py_None) { if (attrib == Py_None) {
Py_DECREF(attrib); Py_DECREF(attrib);
attrib = PyDict_New(); attrib = PyDict_New();
if (!attrib) if (!attrib) {
Py_DECREF(tag);
return; return;
}
} }
res = PyObject_CallFunction(self->handle_start, "OO", tag, attrib); res = PyObject_CallFunction(self->handle_start, "OO", tag, attrib);
} else } else
......
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