]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[2.7] bpo-36291: Fix a possible reference leak in the json module (GH-12330)
authorstratakis <cstratak@redhat.com>
Thu, 14 Mar 2019 15:22:46 +0000 (16:22 +0100)
committerVictor Stinner <vstinner@redhat.com>
Thu, 14 Mar 2019 15:22:46 +0000 (16:22 +0100)
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.

Misc/NEWS.d/next/Library/2019-03-14-15-54-46.bpo-36291.UalHXP.rst [new file with mode: 0644]
Modules/_json.c

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 (file)
index 0000000..07d780c
--- /dev/null
@@ -0,0 +1 @@
+Fix a possible reference leak in the json module.
index 3a88882f0c986b4db7c0d76c450c74b1b1324fa3..050d37daa43c44d768b2cd354a06cad56187d869 100644 (file)
@@ -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);
         }
     }