Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8d979d5

Browse files
Fixed possible reference leaks in the _json module.
2 parents c70225c + 21fe721 commit 8d979d5

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

Modules/_json.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -845,14 +845,16 @@ _parse_array_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssi
845845
int kind;
846846
Py_ssize_t end_idx;
847847
PyObject *val = NULL;
848-
PyObject *rval = PyList_New(0);
848+
PyObject *rval;
849849
Py_ssize_t next_idx;
850-
if (rval == NULL)
851-
return NULL;
852850

853851
if (PyUnicode_READY(pystr) == -1)
854852
return NULL;
855853

854+
rval = PyList_New(0);
855+
if (rval == NULL)
856+
return NULL;
857+
856858
str = PyUnicode_DATA(pystr);
857859
kind = PyUnicode_KIND(pystr);
858860
end_idx = PyUnicode_GET_LENGTH(pystr) - 1;
@@ -1559,8 +1561,11 @@ encoder_listencode_obj(PyEncoderObject *s, _PyAccu *acc,
15591561
return -1;
15601562
}
15611563

1562-
if (Py_EnterRecursiveCall(" while encoding a JSON object"))
1564+
if (Py_EnterRecursiveCall(" while encoding a JSON object")) {
1565+
Py_DECREF(newobj);
1566+
Py_XDECREF(ident);
15631567
return -1;
1568+
}
15641569
rv = encoder_listencode_obj(s, acc, newobj, indent_level);
15651570
Py_LeaveRecursiveCall();
15661571

0 commit comments

Comments
 (0)