Skip to content

Commit

Permalink
Fix a reference leak when sort keys. (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka committed Nov 6, 2017
1 parent ef4015d commit 113039a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions simplejson/_speedups.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 113039a

Please sign in to comment.