]> granicus.if.org Git - python/commitdiff
Fixed possible leaks in ElementTree parser.
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 9 Dec 2015 17:44:30 +0000 (19:44 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 9 Dec 2015 17:44:30 +0000 (19:44 +0200)
Modules/_elementtree.c

index 5d15ed3b1b922d72033625018d6afdcd236940d2..915a0be4d4a254b979f3beb1d6f3f0f83a92a409 100644 (file)
@@ -2935,8 +2935,10 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
     /* attributes */
     if (attrib_in[0]) {
         attrib = PyDict_New();
-        if (!attrib)
+        if (!attrib) {
+            Py_DECREF(tag);
             return;
+        }
         while (attrib_in[0] && attrib_in[1]) {
             PyObject* key = makeuniversal(self, attrib_in[0]);
             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,
                 Py_XDECREF(value);
                 Py_XDECREF(key);
                 Py_DECREF(attrib);
+                Py_DECREF(tag);
                 return;
             }
             ok = PyDict_SetItem(attrib, key, value);
@@ -2951,6 +2954,7 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
             Py_DECREF(key);
             if (ok < 0) {
                 Py_DECREF(attrib);
+                Py_DECREF(tag);
                 return;
             }
             attrib_in += 2;
@@ -2958,8 +2962,10 @@ expat_start_handler(XMLParserObject* self, const XML_Char* tag_in,
     } else {
         /* Pass an empty dictionary on */
         attrib = PyDict_New();
-        if (!attrib)
+        if (!attrib) {
+            Py_DECREF(tag);
             return;
+        }
     }
 
     if (TreeBuilder_CheckExact(self->target)) {