[Python-checkins] cpython (merge 3.5 -> default): Fixed possible leaks in ElementTree parser.

serhiy.storchaka python-checkins at python.org
Wed Dec 9 12:49:34 EST 2015


https://hg.python.org/cpython/rev/5176e8a2e258
changeset:   99517:5176e8a2e258
parent:      99515:bb8b75c6bfdf
parent:      99516:7cb05201f93b
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Wed Dec 09 19:45:07 2015 +0200
summary:
  Fixed possible leaks in ElementTree parser.

files:
  Modules/_elementtree.c |  10 ++++++++--
  1 files changed, 8 insertions(+), 2 deletions(-)


diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -2934,8 +2934,10 @@
     /* 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");
@@ -2943,6 +2945,7 @@
                 Py_XDECREF(value);
                 Py_XDECREF(key);
                 Py_DECREF(attrib);
+                Py_DECREF(tag);
                 return;
             }
             ok = PyDict_SetItem(attrib, key, value);
@@ -2950,6 +2953,7 @@
             Py_DECREF(key);
             if (ok < 0) {
                 Py_DECREF(attrib);
+                Py_DECREF(tag);
                 return;
             }
             attrib_in += 2;
@@ -2957,8 +2961,10 @@
     } else {
         /* Pass an empty dictionary on */
         attrib = PyDict_New();
-        if (!attrib)
+        if (!attrib) {
+            Py_DECREF(tag);
             return;
+        }
     }
 
     if (TreeBuilder_CheckExact(self->target)) {

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list