diff options
-rw-r--r-- | Lib/test/test_compile.py | 4 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Python/compile.c | 1 |
3 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 1a98d2ff9d..0aba1c213d 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -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) @@ -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 diff --git a/Python/compile.c b/Python/compile.c index f40c325bbf..d40357c429 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -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__"); |