]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Plug a memory leak in list(), when appending to the result list.
authorTim Peters <tim.peters@gmail.com>
Wed, 2 May 2001 07:12:39 +0000 (07:12 +0000)
committerTim Peters <tim.peters@gmail.com>
Wed, 2 May 2001 07:12:39 +0000 (07:12 +0000)
Objects/abstract.c

index a5f97a18d0920e7fbf5460a931cb4b4f98829110..8ee1e5a19025c37364fa689c8401fdddb5f94923 100644 (file)
@@ -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;
+                       }
                }
        }