Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a29eb08

Browse files
Fixed possible leaks in ElementTree parser.
1 parent d6a69d8 commit a29eb08

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

Modules/_elementtree.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2935,31 +2935,37 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
29352935
/* attributes */
29362936
if (attrib_in[0]) {
29372937
attrib = PyDict_New();
2938-
if (!attrib)
2938+
if (!attrib) {
2939+
Py_DECREF(tag);
29392940
return;
2941+
}
29402942
while (attrib_in[0] && attrib_in[1]) {
29412943
PyObject* key = makeuniversal(self, attrib_in[0]);
29422944
PyObject* value = PyUnicode_DecodeUTF8(attrib_in[1], strlen(attrib_in[1]), "strict");
29432945
if (!key || !value) {
29442946
Py_XDECREF(value);
29452947
Py_XDECREF(key);
29462948
Py_DECREF(attrib);
2949+
Py_DECREF(tag);
29472950
return;
29482951
}
29492952
ok = PyDict_SetItem(attrib, key, value);
29502953
Py_DECREF(value);
29512954
Py_DECREF(key);
29522955
if (ok < 0) {
29532956
Py_DECREF(attrib);
2957+
Py_DECREF(tag);
29542958
return;
29552959
}
29562960
attrib_in += 2;
29572961
}
29582962
} else {
29592963
/* Pass an empty dictionary on */
29602964
attrib = PyDict_New();
2961-
if (!attrib)
2965+
if (!attrib) {
2966+
Py_DECREF(tag);
29622967
return;
2968+
}
29632969
}
29642970

29652971
if (TreeBuilder_CheckExact(self->target)) {

0 commit comments

Comments
 (0)