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

Skip to content

Commit 3d74976

Browse files
Issue #26718: super.__init__ no longer leaks memory if called multiple times.
NOTE: A direct call of super.__init__ is not endorsed!
1 parent a3c532b commit 3d74976

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
@@ -7336,9 +7336,9 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds)
73367336
Py_INCREF(obj);
73377337
}
73387338
Py_INCREF(type);
7339-
su->type = type;
7340-
su->obj = obj;
7341-
su->obj_type = obj_type;
7339+
Py_XSETREF(su->type, type);
7340+
Py_XSETREF(su->obj, obj);
7341+
Py_XSETREF(su->obj_type, obj_type);
73427342
return 0;
73437343
}
73447344

0 commit comments

Comments
 (0)