summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-11-06 21:18:51 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2017-11-06 21:18:51 +0200
commit634935dfc8ca2379e0119b6f3addbf334538c842 (patch)
tree1db18ec165fa7c4b3ce0efe6dfe8eb8200694e68
parentef4015d1d997c234d2bb604b4d858e04cdbceeb3 (diff)
downloadsimplejson-sort-refleak.tar.gz
Fix a reference leak when sort keys.sort-refleak
-rw-r--r--simplejson/_speedups.c7
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);