builtin_map(): A better fix for the previous leak plug (remember
authorBarry Warsaw <barry@python.org>
Thu, 28 Jan 1999 18:49:12 +0000 (18:49 +0000)
committerBarry Warsaw <barry@python.org>
Thu, 28 Jan 1999 18:49:12 +0000 (18:49 +0000)
PyList_Append steals a reference even if it fails).

builtin_filter(): Had the same leak problem as builtin_map().

Python/bltinmodule.c

index 1929ae92ba7f3ca375f15f2105a97f971a12239e..b0d0648c0f0d16b8b6329f845d48e8d56573cdbf 100644 (file)
@@ -232,8 +232,10 @@ builtin_filter(self, args)
                                        goto Fail_1;
                        }
                        else {
+                               int status = PyList_Append(result, item);
                                j++;
-                               if (PyList_Append(result, item) < 0)
+                               Py_DECREF(item);
+                               if (status < 0)
                                        goto Fail_1;
                        }
                } else {
@@ -901,9 +903,10 @@ builtin_map(self, args)
                                goto Fail_1;
                }
                if (i >= len) {
-                       if (PyList_Append(result, value) < 0)
-                               goto Fail_1;
+                       int status = PyList_Append(result, value);
                        Py_DECREF(value);
+                       if (status < 0)
+                               goto Fail_1;
                }
                else {
                        if (PyList_SetItem(result, i, value) < 0)