Skip to content

Commit d85c272

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 cc279f4 commit d85c272

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
@@ -245,8 +245,10 @@ string_intern(xmlparseobject *self, const char* str)
245245
if (!value) {
246246
if (PyDict_SetItem(self->intern, result, result) == 0)
247247
return result;
248-
else
248+
else {
249+
Py_DECREF(result);
249250
return NULL;
251+
}
250252
}
251253
Py_INCREF(value);
252254
Py_DECREF(result);
@@ -395,6 +397,7 @@ my_StartElementHandler(void *userData,
395397
flag_error(self);
396398
Py_DECREF(n);
397399
Py_DECREF(v);
400+
Py_DECREF(container);
398401
return;
399402
}
400403
else {
@@ -403,12 +406,14 @@ my_StartElementHandler(void *userData,
403406
}
404407
}
405408
args = string_intern(self, name);
406-
if (args != NULL)
407-
args = Py_BuildValue("(NN)", args, container);
408409
if (args == NULL) {
409410
Py_DECREF(container);
410411
return;
411412
}
413+
args = Py_BuildValue("(NN)", args, container);
414+
if (args == NULL) {
415+
return;
416+
}
412417
/* Container is now a borrowed reference; ignore it. */
413418
self->in_callback = 1;
414419
rv = call_with_frame("StartElement", __LINE__,
@@ -567,7 +572,6 @@ my_ElementDeclHandler(void *userData,
567572
}
568573
args = Py_BuildValue("NN", nameobj, modelobj);
569574
if (args == NULL) {
570-
Py_DECREF(modelobj);
571575
flag_error(self);
572576
goto finally;
573577
}

0 commit comments

Comments
 (0)