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

(cherry picked from commit 68def052dc)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
This commit is contained in:
Miss Islington (bot) 2018-10-19 00:16:25 -07:00 committed by GitHub
parent 2bc1e8c909
commit d6d35d0a00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -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;
}