Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 131b8f8

Browse files
Issue #26718: super.__init__ no longer leaks memory if called multiple times.
NOTE: A direct call of super.__init__ is not endorsed!
2 parents 6fce353 + 3d74976 commit 131b8f8

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

Lib/test/test_super.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ def g():
171171
c = f().__closure__[0]
172172
self.assertRaises(TypeError, X.meth, c)
173173

174+
def test_super_init_leaks(self):
175+
# Issue #26718: super.__init__ leaked memory if called multiple times.
176+
# This will be caught by regrtest.py -R if this leak.
177+
# NOTE: Despite the use in the test a direct call of super.__init__
178+
# is not endorsed.
179+
sp = super(float, 1.0)
180+
for i in range(1000):
181+
super.__init__(sp, int, i)
182+
174183

175184
if __name__ == "__main__":
176185
unittest.main()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: tba
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #26718: super.__init__ no longer leaks memory if called multiple times.
14+
NOTE: A direct call of super.__init__ is not endorsed!
15+
1316
- Issue #25339: PYTHONIOENCODING now has priority over locale in setting the
1417
error handler for stdin and stdout.
1518

Objects/typeobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7350,9 +7350,9 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds)
73507350
Py_INCREF(obj);
73517351
}
73527352
Py_INCREF(type);
7353-
su->type = type;
7354-
su->obj = obj;
7355-
su->obj_type = obj_type;
7353+
Py_XSETREF(su->type, type);
7354+
Py_XSETREF(su->obj, obj);
7355+
Py_XSETREF(su->obj_type, obj_type);
73567356
return 0;
73577357
}
73587358

0 commit comments

Comments
 (0)