From: Tim Peters Date: Wed, 2 May 2001 07:12:39 +0000 (+0000) Subject: Plug a memory leak in list(), when appending to the result list. X-Git-Tag: v2.2a3~1935 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6ad22c41c2f1adb39d023d8dcc779d96d73695f6;p=thirdparty%2FPython%2Fcpython.git Plug a memory leak in list(), when appending to the result list. --- diff --git a/Objects/abstract.c b/Objects/abstract.c index a5f97a18d092..8ee1e5a19025 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1291,11 +1291,15 @@ PySequence_List(PyObject *v) break; } if (i < n) - PyList_SET_ITEM(result, i, item); - else if (PyList_Append(result, item) < 0) { - Py_DECREF(result); - result = NULL; - break; + PyList_SET_ITEM(result, i, item); /* steals ref */ + else { + int status = PyList_Append(result, item); + Py_DECREF(item); /* append creates a new ref */ + if (status < 0) { + Py_DECREF(result); + result = NULL; + break; + } } }