Skip to content

Commit 7d00562

Browse files
committed
only use items locally in encoder_listencode_dict
1 parent 5173373 commit 7d00562

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Modules/_json.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,6 @@ encoder_listencode_dict(PyEncoderObject *s, PyUnicodeWriter *writer,
16951695
{
16961696
/* Encode Python dict dct a JSON term */
16971697
PyObject *ident = NULL;
1698-
PyObject *items = NULL;
16991698
bool first = true;
17001699

17011700
if (PyDict_GET_SIZE(dct) == 0) {
@@ -1732,8 +1731,9 @@ encoder_listencode_dict(PyEncoderObject *s, PyUnicodeWriter *writer,
17321731
}
17331732

17341733
if (s->sort_keys || !PyDict_CheckExact(dct)) {
1735-
items = PyMapping_Items(dct);
1734+
PyObject *items = PyMapping_Items(dct);
17361735
if (items == NULL || (s->sort_keys && PyList_Sort(items) < 0)) {
1736+
Py_XDECREF(items);
17371737
goto bail;
17381738
}
17391739

@@ -1742,9 +1742,8 @@ encoder_listencode_dict(PyEncoderObject *s, PyUnicodeWriter *writer,
17421742
result = _encoder_iterate_mapping_lock_held(s, writer, &first, dct,
17431743
items, indent_level, indent_cache, separator);
17441744
Py_END_CRITICAL_SECTION_SEQUENCE_FAST();
1745-
Py_CLEAR(items);
1745+
Py_DECREF(items);
17461746
if (result < 0) {
1747-
Py_XDECREF(items);
17481747
goto bail;
17491748
}
17501749

@@ -1777,7 +1776,6 @@ encoder_listencode_dict(PyEncoderObject *s, PyUnicodeWriter *writer,
17771776
return 0;
17781777

17791778
bail:
1780-
Py_XDECREF(items);
17811779
Py_XDECREF(ident);
17821780
return -1;
17831781
}

0 commit comments

Comments
 (0)