[Python-checkins] Fix several reference counting bugs in pyexpat.c. (GH-9955)

Miss Islington (bot) webhook-mailer at python.org
Fri Oct 19 03:16:29 EDT 2018


https://github.com/python/cpython/commit/d6d35d0a005bb3d1e04095074c255bf8d0b651d7
commit: d6d35d0a005bb3d1e04095074c255bf8d0b651d7
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-10-19T00:16:25-07:00
summary:

Fix several reference counting bugs in pyexpat.c. (GH-9955)

(cherry picked from commit 68def052dcd41313eff2bd9f269e22c5a941db4d)

Co-authored-by: Zackery Spytz <zspytz at gmail.com>

files:
M Modules/pyexpat.c

diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index c52079e518f2..ab3dac6db168 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -243,8 +243,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);
@@ -393,6 +395,7 @@ my_StartElementHandler(void *userData,
                 flag_error(self);
                 Py_DECREF(n);
                 Py_DECREF(v);
+                Py_DECREF(container);
                 return;
             }
             else {
@@ -401,12 +404,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__,
@@ -565,7 +570,6 @@ my_ElementDeclHandler(void *userData,
         }
         args = Py_BuildValue("NN", nameobj, modelobj);
         if (args == NULL) {
-            Py_DECREF(modelobj);
             flag_error(self);
             goto finally;
         }



More information about the Python-checkins mailing list