[3.6] bpo-30936: Fix a reference leak in json when fail to sort keys. (GH-2712). (#2727)

(cherry picked from commit 49f6449ef4)
This commit is contained in:
Serhiy Storchaka 2017-07-16 07:48:08 +03:00 committed by GitHub
parent 28343e3392
commit a819e5e1e6
2 changed files with 7 additions and 1 deletions

View file

@ -1601,8 +1601,10 @@ encoder_listencode_dict(PyEncoderObject *s, _PyAccu *acc,
if (items == NULL)
goto bail;
sortkeys = PyObject_IsTrue(s->sort_keys);
if (sortkeys < 0 || (sortkeys && PyList_Sort(items) < 0))
if (sortkeys < 0 || (sortkeys && PyList_Sort(items) < 0)) {
Py_DECREF(items);
goto bail;
}
it = PyObject_GetIter(items);
Py_DECREF(items);
if (it == NULL)