Commits

Anonymous committed 11d206a

Added Jeff Senn's generator leakage test and a fix for the bug it reproduced.
http://www.stackless.com/pipermail/stackless/2006-December/002144.html

  • Participants
  • Parent commits 7ff76b7
  • Branches release25-maint

Comments (0)

Files changed (2)

File Stackless/core/stacklesseval.c

 
 	if (!result || f->f_stacktop == NULL) {
 		/* generator can't be rerun, so release the frame */
+		Py_DECREF(f);
 		gen->gi_frame = NULL;
 	}
 

File Stackless/unittests/test_generator.py

+import unittest
+import gc
+
+def f(): yield 1
+
+class TestGarbageCollection(unittest.TestCase):
+    def testSimpleLeakage(self):
+        leakage = []
+
+        gc.collect(2)
+        before  = gc.get_objects()
+
+        for i in f():
+            pass
+
+        gc.collect(2)
+        after = gc.get_objects()
+
+        for x in after:
+            if x is not before and x is not after and x not in before:
+                leakage.append(x)
+
+        if len(leakage):
+            self.failUnless(len(leakage) == 0, "Leaked %s" % repr(leakage))