From de1c7d52527e1d84c131f4801d2dc3d0236b5b25 Mon Sep 17 00:00:00 2001 From: svelankar Date: Thu, 9 Mar 2017 00:27:48 -0500 Subject: [PATCH] Issue #29682:Possible missing NULL check in pyexpat (#573) --- Modules/pyexpat.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index a95c3885fa2c..7f95bb80e03f 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -1312,6 +1312,13 @@ newxmlparseobject(char *encoding, char *namespace_separator, PyObject *intern) else { self->itself = XML_ParserCreate(encoding); } + if (self->itself == NULL) { + PyErr_SetString(PyExc_RuntimeError, + "XML_ParserCreate failed"); + Py_DECREF(self); + return NULL; + } + #if ((XML_MAJOR_VERSION >= 2) && (XML_MINOR_VERSION >= 1)) || defined(XML_HAS_SET_HASH_SALT) /* This feature was added upstream in libexpat 2.1.0. Our expat copy * 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) #else PyObject_GC_Init(self); #endif - if (self->itself == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "XML_ParserCreate failed"); - Py_DECREF(self); - return NULL; - } XML_SetUserData(self->itself, (void *)self); #ifdef Py_USING_UNICODE XML_SetUnknownEncodingHandler(self->itself, -- 2.47.3