]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix several reference counting bugs in pyexpat.c. (GH-9955)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 19 Oct 2018 07:25:00 +0000 (00:25 -0700)
committerGitHub <noreply@github.com>
Fri, 19 Oct 2018 07:25:00 +0000 (00:25 -0700)
(cherry picked from commit 68def052dcd41313eff2bd9f269e22c5a941db4d)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Modules/pyexpat.c

index aa21d93c115aaf4d3f0b0c7443f384fefbe02270..2e69f61190d094da7967de868ee0d76c90a6d6f5 100644 (file)
@@ -245,8 +245,10 @@ string_intern(xmlparseobject *self, const char* str)
     if (!value) {
         if (PyDict_SetItem(self->intern, result, result) == 0)
             return result;
-        else
+        else {
+            Py_DECREF(result);
             return NULL;
+        }
     }
     Py_INCREF(value);
     Py_DECREF(result);
@@ -395,6 +397,7 @@ my_StartElementHandler(void *userData,
                 flag_error(self);
                 Py_DECREF(n);
                 Py_DECREF(v);
+                Py_DECREF(container);
                 return;
             }
             else {
@@ -403,12 +406,14 @@ my_StartElementHandler(void *userData,
             }
         }
         args = string_intern(self, name);
-        if (args != NULL)
-            args = Py_BuildValue("(NN)", args, container);
         if (args == NULL) {
             Py_DECREF(container);
             return;
         }
+        args = Py_BuildValue("(NN)", args, container);
+        if (args == NULL) {
+            return;
+        }
         /* Container is now a borrowed reference; ignore it. */
         self->in_callback = 1;
         rv = call_with_frame("StartElement", __LINE__,
@@ -567,7 +572,6 @@ my_ElementDeclHandler(void *userData,
         }
         args = Py_BuildValue("NN", nameobj, modelobj);
         if (args == NULL) {
-            Py_DECREF(modelobj);
             flag_error(self);
             goto finally;
         }