Skip to content

Commit d6d35d0

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 2bc1e8c commit d6d35d0

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
@@ -243,8 +243,10 @@ string_intern(xmlparseobject *self, const char* str)
243243
if (!value) {
244244
if (PyDict_SetItem(self->intern, result, result) == 0)
245245
return result;
246-
else
246+
else {
247+
Py_DECREF(result);
247248
return NULL;
249+
}
248250
}
249251
Py_INCREF(value);
250252
Py_DECREF(result);
@@ -393,6 +395,7 @@ my_StartElementHandler(void *userData,
393395
flag_error(self);
394396
Py_DECREF(n);
395397
Py_DECREF(v);
398+
Py_DECREF(container);
396399
return;
397400
}
398401
else {
@@ -401,12 +404,14 @@ my_StartElementHandler(void *userData,
401404
}
402405
}
403406
args = string_intern(self, name);
404-
if (args != NULL)
405-
args = Py_BuildValue("(NN)", args, container);
406407
if (args == NULL) {
407408
Py_DECREF(container);
408409
return;
409410
}
411+
args = Py_BuildValue("(NN)", args, container);
412+
if (args == NULL) {
413+
return;
414+
}
410415
/* Container is now a borrowed reference; ignore it. */
411416
self->in_callback = 1;
412417
rv = call_with_frame("StartElement", __LINE__,
@@ -565,7 +570,6 @@ my_ElementDeclHandler(void *userData,
565570
}
566571
args = Py_BuildValue("NN", nameobj, modelobj);
567572
if (args == NULL) {
568-
Py_DECREF(modelobj);
569573
flag_error(self);
570574
goto finally;
571575
}

0 commit comments

Comments
 (0)