From: stratakis Date: Thu, 14 Mar 2019 15:22:46 +0000 (+0100) Subject: [2.7] bpo-36291: Fix a possible reference leak in the json module (GH-12330) X-Git-Tag: v2.7.17rc1~120 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb3336acfde3204fd01ce519ef24cc18a94dfa3f;p=thirdparty%2FPython%2Fcpython.git [2.7] bpo-36291: Fix a possible reference leak in the json module (GH-12330) Fix a reference leak in json if parsing a floating point number fails. If PyOS_string_to_double() fails in _match_number_str(): decrement numstr ref counter. --- diff --git a/Misc/NEWS.d/next/Library/2019-03-14-15-54-46.bpo-36291.UalHXP.rst b/Misc/NEWS.d/next/Library/2019-03-14-15-54-46.bpo-36291.UalHXP.rst new file mode 100644 index 000000000000..07d780cd7fd6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-03-14-15-54-46.bpo-36291.UalHXP.rst @@ -0,0 +1 @@ +Fix a possible reference leak in the json module. diff --git a/Modules/_json.c b/Modules/_json.c index 3a88882f0c98..050d37daa43c 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -1375,8 +1375,10 @@ _match_number_str(PyScannerObject *s, PyObject *pystr, Py_ssize_t start, Py_ssiz else { double d = PyOS_string_to_double(PyString_AS_STRING(numstr), NULL, NULL); - if (d == -1.0 && PyErr_Occurred()) + if (d == -1.0 && PyErr_Occurred()) { + Py_DECREF(numstr); return NULL; + } rval = PyFloat_FromDouble(d); } }