]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
fix subtle refcount big in filter() -- Tim MacKenzie
authorGuido van Rossum <guido@python.org>
Tue, 10 Jan 1995 17:40:55 +0000 (17:40 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 10 Jan 1995 17:40:55 +0000 (17:40 +0000)
Python/bltinmodule.c

index f47b4085e29e01f3a01283c2f1ada32a0e74f190..b3ac3c6a555cf7a2e5ff81d351a766e44f20ca49 100644 (file)
@@ -186,21 +186,22 @@ builtin_filter(self, args)
 
                if (func == None) {
                        good = item;
+                       INCREF(good);
                }
                else {
                        object *arg = mkvalue("(O)", item);
-                       DECREF(item);
                        if (arg == NULL)
                                goto Fail_1;
                        good = call_object(func, arg);
                        DECREF(arg);
-                       if (good == NULL)
+                       if (good == NULL) {
+                               DECREF(item);
                                goto Fail_1;
+                       }
                }
                ok = testbool(good);
                DECREF(good);
                if (ok) {
-                       INCREF(item);
                        if (j < len) {
                                if (setlistitem(result, j++, item) < 0)
                                        goto Fail_1;
@@ -210,6 +211,8 @@ builtin_filter(self, args)
                                if (addlistitem(result, item) < 0)
                                        goto Fail_1;
                        }
+               } else {
+                       DECREF(item);
                }
        }