Skip to content

Commit df47d09

Browse files
Backport PR #45489: Bug tojson memleak (#45545)
Co-authored-by: vernetya <[email protected]>
1 parent ab51981 commit df47d09

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

Diff for: doc/source/whatsnew/v1.4.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ I/O
966966
- Bug in :func:`read_json` raising ``ValueError`` when attempting to parse json strings containing "://" (:issue:`36271`)
967967
- Bug in :func:`read_csv` when ``engine="c"`` and ``encoding_errors=None`` which caused a segfault (:issue:`45180`)
968968
- Bug in :func:`read_csv` an invalid value of ``usecols`` leading to an unclosed file handle (:issue:`45384`)
969+
- Bug in :meth:`DataFrame.to_json` fix memory leak (:issue:`43877`)
969970

970971
Period
971972
^^^^^^

Diff for: pandas/_libs/src/ujson/python/objToJSON.c

+1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ static PyObject *get_values(PyObject *obj) {
228228
PyErr_Clear();
229229
} else if (PyObject_HasAttrString(values, "__array__")) {
230230
// We may have gotten a Categorical or Sparse array so call np.array
231+
Py_DECREF(values);
231232
values = PyObject_CallMethod(values, "__array__", NULL);
232233
} else if (!PyArray_CheckExact(values)) {
233234
// Didn't get a numpy array, so keep trying

0 commit comments

Comments
 (0)