From 052bcb89e5ae926dd0c7ba47ff7ff3465ceffe3a Mon Sep 17 00:00:00 2001 From: Anselm Kruis Date: Mon, 13 Feb 2017 22:22:27 +0100 Subject: [PATCH] Issue #117: fix a reference leak in stackless.threads Fix two reference leaks in the C-implementation of stackless.threads. https://bitbucket.org/stackless-dev/stackless/issues/117 (grafted from 0ed22581e9fc255195d9116446ab9b20bcf99ac8) --- Stackless/changelog.txt | 3 ++- Stackless/module/stacklessmodule.c | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Stackless/changelog.txt b/Stackless/changelog.txt index 9cef8647c044ae..ca3361844a6013 100644 --- a/Stackless/changelog.txt +++ b/Stackless/changelog.txt @@ -21,7 +21,8 @@ What's New in Stackless 3.X.X? - https://bitbucket.org/stackless-dev/stackless/issues/117 Fix various reference leaks: - Leak of a reference to Py_None in generator.throw() - + - Leak of a reference to the thread-id of every thread returned by stackless.threads + Additionally this change brings the handling of caught exceptions more in line with C-Python. diff --git a/Stackless/module/stacklessmodule.c b/Stackless/module/stacklessmodule.c index 4dce66d898a0bb..30ab5f8806fb96 100644 --- a/Stackless/module/stacklessmodule.c +++ b/Stackless/module/stacklessmodule.c @@ -1524,9 +1524,16 @@ slpmodule_getthreads(PyObject *self) for (ts = interp->tstate_head; ts != NULL; ts = ts->next) { PyObject *id = PyLong_FromLong(ts->thread_id); - - if (id == NULL || PyList_Append(lis, id)) + if (id == NULL) { + Py_DECREF(lis); + return NULL; + } + if (PyList_Append(lis, id)) { + Py_DECREF(lis); + Py_DECREF(id); return NULL; + } + Py_DECREF(id); } PyList_Reverse(lis); return lis;