Commits

Anonymous committed 84b61fe

fix subtle refcount big in filter() -- Tim MacKenzie

  • Participants
  • Parent commits 1dae0d3
  • Branches legacy-trunk

Comments (0)

Files changed (1)

Python/bltinmodule.c

 
 		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;
 				if (addlistitem(result, item) < 0)
 					goto Fail_1;
 			}
+		} else {
+			DECREF(item);
 		}
 	}