Kaydet (Commit) 49f6449e authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka Kaydeden (comit) GitHub

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

üst 95bebb72
......@@ -44,3 +44,7 @@ class TestEncode(CTest):
self.assertRaises(ZeroDivisionError, test, 'check_circular')
self.assertRaises(ZeroDivisionError, test, 'allow_nan')
self.assertRaises(ZeroDivisionError, test, 'sort_keys')
def test_unsortable_keys(self):
with self.assertRaises(TypeError):
self.json.encoder.JSONEncoder(sort_keys=True).encode({'a': 1, 1: 'a'})
......@@ -1589,8 +1589,10 @@ encoder_listencode_dict(PyEncoderObject *s, _PyAccu *acc,
items = PyMapping_Items(dct);
if (items == NULL)
goto bail;
if (s->sort_keys && PyList_Sort(items) < 0)
if (s->sort_keys && PyList_Sort(items) < 0) {
Py_DECREF(items);
goto bail;
}
it = PyObject_GetIter(items);
Py_DECREF(items);
if (it == NULL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment