]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #26718: super.__init__ no longer leaks memory if called multiple times.
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 13 Apr 2016 12:27:33 +0000 (15:27 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 13 Apr 2016 12:27:33 +0000 (15:27 +0300)
NOTE: A direct call of super.__init__ is not endorsed!

Lib/test/test_super.py
Misc/NEWS
Objects/typeobject.c

index dc3a15f8356572f41f63a14ef4beb9ed78c3acf7..b84863fe53c6ec5e13f6625acdbe0dd39df13c98 100644 (file)
@@ -171,6 +171,15 @@ class TestSuper(unittest.TestCase):
         c = f().__closure__[0]
         self.assertRaises(TypeError, X.meth, c)
 
+    def test_super_init_leaks(self):
+        # Issue #26718: super.__init__ leaked memory if called multiple times.
+        # This will be caught by regrtest.py -R if this leak.
+        # NOTE: Despite the use in the test a direct call of super.__init__
+        # is not endorsed.
+        sp = super(float, 1.0)
+        for i in range(1000):
+            super.__init__(sp, int, i)
+
 
 if __name__ == "__main__":
     unittest.main()
index d1227f53067c7ae440619df1a17f6b559fc73ab7..37dc45333d708ef53c2cff37d272a636707c1472 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ Release date: tba
 Core and Builtins
 -----------------
 
+- Issue #26718: super.__init__ no longer leaks memory if called multiple times.
+  NOTE: A direct call of super.__init__ is not endorsed!
+
 - Issue #25339: PYTHONIOENCODING now has priority over locale in setting the
   error handler for stdin and stdout.
 
index f88a5fbe5166c7fe8116e90c9037c21912c0bacc..3a09af571562d7a7ec6f3e305737f9bd54f33580 100644 (file)
@@ -7336,9 +7336,9 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds)
         Py_INCREF(obj);
     }
     Py_INCREF(type);
-    su->type = type;
-    su->obj = obj;
-    su->obj_type = obj_type;
+    Py_XSETREF(su->type, type);
+    Py_XSETREF(su->obj, obj);
+    Py_XSETREF(su->obj_type, obj_type);
     return 0;
 }