]> granicus.if.org Git - python/commitdiff
Fix a reference leak found by Georg, when compiling a class nested in another class.
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Fri, 28 Mar 2008 20:45:42 +0000 (20:45 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Fri, 28 Mar 2008 20:45:42 +0000 (20:45 +0000)
Test is run with "regrtest.py -R:: test_compile"

Backport of r62015

Lib/test/test_compile.py
Misc/NEWS
Python/compile.c

index 1a98d2ff9d4deb04c2345cfdaea1f8d860a74d8d..0aba1c213d2db5793f97835eb99f845ec9c1216b 100644 (file)
@@ -398,6 +398,10 @@ if 1:
         del d[..., ...]
         self.assertEqual((Ellipsis, Ellipsis) in d, False)
 
+    def test_nested_classes(self):
+        # Verify that it does not leak
+        compile("class A:\n    class B: pass", 'tmp', 'exec')
+
 def test_main():
     test_support.run_unittest(TestSpecifics)
 
index 695e71b6f5452389cb6fcc1f1182b54f04ecb5f0..c914050134ad67c2090fd54d5429d545a8b29340 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.5.3?
 Core and builtins
 -----------------
 
+- The compilation of a class nested in another class used to leak one
+  reference on the outer class name.
+
 - Issue #1477: With narrow Unicode builds, the unicode escape sequence
   \Uxxxxxxxx did not accept values outside the Basic Multilingual Plane.  This
   affected raw unicode literals and the 'raw-unicode-escape' codec.  Now
index f40c325bbfe69f0195be803b82b8604d79e93868..d40357c42979ca12429c207af4f80e9c97970ec6 100644 (file)
@@ -2061,6 +2061,7 @@ compiler_class(struct compiler *c, stmt_ty s)
        if (!compiler_enter_scope(c, s->v.ClassDef.name, (void *)s,
                                  s->lineno))
                return 0;
+       Py_XDECREF(c->u->u_private);
        c->u->u_private = s->v.ClassDef.name;
        Py_INCREF(c->u->u_private);
        str = PyString_InternFromString("__name__");