summaryrefslogtreecommitdiffstats
path: root/Objects/abstract.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-05-02 07:12:39 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-05-02 07:12:39 (GMT)
commit6ad22c41c2f1adb39d023d8dcc779d96d73695f6 (patch)
tree9013aee86d405a3be577962b1378d5a5296c1880 /Objects/abstract.c
parent8ae2df483c4682dead74ea0584f4d61955621667 (diff)
downloadcpython-6ad22c41c2f1adb39d023d8dcc779d96d73695f6.zip
cpython-6ad22c41c2f1adb39d023d8dcc779d96d73695f6.tar.gz
cpython-6ad22c41c2f1adb39d023d8dcc779d96d73695f6.tar.bz2
Plug a memory leak in list(), when appending to the result list.
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r--Objects/abstract.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index a5f97a1..8ee1e5a 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;
+ }
}
}