[Python-checkins] cpython (merge 3.5 -> default): Issue #26718: super.__init__ no longer leaks memory if called multiple times.

serhiy.storchaka python-checkins at python.org
Wed Apr 13 08:29:59 EDT 2016


https://hg.python.org/cpython/rev/55f4c1f8ca6a
changeset:   100960:55f4c1f8ca6a
parent:      100956:ad5b079565ad
parent:      100958:450f36750cb9
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Wed Apr 13 15:28:53 2016 +0300
summary:
  Issue #26718: super.__init__ no longer leaks memory if called multiple times.
NOTE: A direct call of super.__init__ is not endorsed!

files:
  Lib/test/test_super.py |  9 +++++++++
  Misc/NEWS              |  3 +++
  Objects/typeobject.c   |  6 +++---
  3 files changed, 15 insertions(+), 3 deletions(-)


diff --git a/Lib/test/test_super.py b/Lib/test/test_super.py
--- a/Lib/test/test_super.py
+++ b/Lib/test/test_super.py
@@ -171,6 +171,15 @@
         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()
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 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.
 
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -7350,9 +7350,9 @@
         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;
 }
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list