diff options
author | stratakis <cstratak@redhat.com> | 2019-03-14 15:22:46 (GMT) |
---|---|---|
committer | Victor Stinner <vstinner@redhat.com> | 2019-03-14 15:22:46 (GMT) |
commit | fb3336acfde3204fd01ce519ef24cc18a94dfa3f (patch) | |
tree | d9245e1f8849434899940f5457b39c8b5e10751b | |
parent | 2832ad53358e3fbc4bdc601b9f3fa04dd0deae46 (diff) | |
download | cpython-fb3336acfde3204fd01ce519ef24cc18a94dfa3f.zip cpython-fb3336acfde3204fd01ce519ef24cc18a94dfa3f.tar.gz cpython-fb3336acfde3204fd01ce519ef24cc18a94dfa3f.tar.bz2 |
[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.
-rw-r--r-- | Misc/NEWS.d/next/Library/2019-03-14-15-54-46.bpo-36291.UalHXP.rst | 1 | ||||
-rw-r--r-- | Modules/_json.c | 4 |
2 files changed, 4 insertions, 1 deletions
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 0000000..07d780c --- /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 3a88882..050d37d 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); } } |