Skip to content

Commit 5744a33

Browse files
Fix several reference counting bugs in pyexpat.c. (GH-9955)
(cherry picked from commit 68def05) Co-authored-by: Zackery Spytz <[email protected]>
1 parent 6e57382 commit 5744a33

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Modules/pyexpat.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,10 @@ string_intern(xmlparseobject *self, const char* str)
398398
if (!value) {
399399
if (PyDict_SetItem(self->intern, result, result) == 0)
400400
return result;
401-
else
401+
else {
402+
Py_DECREF(result);
402403
return NULL;
404+
}
403405
}
404406
Py_INCREF(value);
405407
Py_DECREF(result);
@@ -547,6 +549,7 @@ my_StartElementHandler(void *userData,
547549
flag_error(self);
548550
Py_DECREF(n);
549551
Py_DECREF(v);
552+
Py_DECREF(container);
550553
return;
551554
}
552555
else {
@@ -555,12 +558,14 @@ my_StartElementHandler(void *userData,
555558
}
556559
}
557560
args = string_intern(self, name);
558-
if (args != NULL)
559-
args = Py_BuildValue("(NN)", args, container);
560561
if (args == NULL) {
561562
Py_DECREF(container);
562563
return;
563564
}
565+
args = Py_BuildValue("(NN)", args, container);
566+
if (args == NULL) {
567+
return;
568+
}
564569
/* Container is now a borrowed reference; ignore it. */
565570
self->in_callback = 1;
566571
rv = call_with_frame(getcode(StartElement, "StartElement", __LINE__),
@@ -742,7 +747,6 @@ my_ElementDeclHandler(void *userData,
742747
}
743748
args = Py_BuildValue("NN", nameobj, modelobj);
744749
if (args == NULL) {
745-
Py_DECREF(modelobj);
746750
flag_error(self);
747751
goto finally;
748752
}

0 commit comments

Comments
 (0)