diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-11-06 23:11:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-06 23:11:10 +0200 |
commit | 113039ae96e670b8f7441d5b1d2c40d9b0b75f56 (patch) | |
tree | 1db18ec165fa7c4b3ce0efe6dfe8eb8200694e68 /simplejson | |
parent | ef4015d1d997c234d2bb604b4d858e04cdbceeb3 (diff) | |
download | simplejson-113039ae96e670b8f7441d5b1d2c40d9b0b75f56.tar.gz |
Fix a reference leak when sort keys. (#186)
Diffstat (limited to 'simplejson')
-rw-r--r-- | simplejson/_speedups.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/simplejson/_speedups.c b/simplejson/_speedups.c index 7b46d8a..e4620b5 100644 --- a/simplejson/_speedups.c +++ b/simplejson/_speedups.c @@ -692,7 +692,8 @@ encoder_dict_iteritems(PyEncoderObject *s, PyObject *dct) PyObject *lst = NULL; PyObject *item = NULL; PyObject *kstr = NULL; - static PyObject *sortfun = NULL; + PyObject *sortfun = NULL; + PyObject *sortres; static PyObject *sortargs = NULL; if (sortargs == NULL) { @@ -763,8 +764,10 @@ encoder_dict_iteritems(PyEncoderObject *s, PyObject *dct) sortfun = PyObject_GetAttrString(lst, "sort"); if (sortfun == NULL) goto bail; - if (!PyObject_Call(sortfun, sortargs, s->item_sort_kw)) + sortres = PyObject_Call(sortfun, sortargs, s->item_sort_kw); + if (!sortres) goto bail; + Py_DECREF(sortres); Py_CLEAR(sortfun); iter = PyObject_GetIter(lst); Py_CLEAR(lst); |