Skip to content

Commit de1c7d5

Browse files
soolabettuserhiy-storchaka
authored andcommitted
Issue #29682:Possible missing NULL check in pyexpat (#573)
1 parent 9fbb65e commit de1c7d5

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Modules/pyexpat.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,13 @@ newxmlparseobject(char *encoding, char *namespace_separator, PyObject *intern)
13121312
else {
13131313
self->itself = XML_ParserCreate(encoding);
13141314
}
1315+
if (self->itself == NULL) {
1316+
PyErr_SetString(PyExc_RuntimeError,
1317+
"XML_ParserCreate failed");
1318+
Py_DECREF(self);
1319+
return NULL;
1320+
}
1321+
13151322
#if ((XML_MAJOR_VERSION >= 2) && (XML_MINOR_VERSION >= 1)) || defined(XML_HAS_SET_HASH_SALT)
13161323
/* This feature was added upstream in libexpat 2.1.0. Our expat copy
13171324
* has a backport of this feature where we also define XML_HAS_SET_HASH_SALT
@@ -1326,12 +1333,6 @@ newxmlparseobject(char *encoding, char *namespace_separator, PyObject *intern)
13261333
#else
13271334
PyObject_GC_Init(self);
13281335
#endif
1329-
if (self->itself == NULL) {
1330-
PyErr_SetString(PyExc_RuntimeError,
1331-
"XML_ParserCreate failed");
1332-
Py_DECREF(self);
1333-
return NULL;
1334-
}
13351336
XML_SetUserData(self->itself, (void *)self);
13361337
#ifdef Py_USING_UNICODE
13371338
XML_SetUnknownEncodingHandler(self->itself,

0 commit comments

Comments
 (0)