New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
super.__init__ leaks memory if called multiple times #70905
Comments
The super() __init__ function fills in the fields of a super object without checking if they were already set. If someone happens to call __init__ again, the previously-set references will end up getting forgotten and leak memory. For example: import sys
print(sys.gettotalrefcount())
sp = super(int, 1)
for i in range(100000):
super.__init__(sp, float, 1.0)
print(sys.gettotalrefcount()) |
If super used __new__ instead of __init__, this issue probably wouldn't arise. I'm surprised that super is subclassable. |
Any uses of super() beyond the documented idioms are uninteresting, except they should not be usable as crash or DoS vectors. |
Based on Guido's feedback and the fact that this isn't documented usage of super() and hence no promises to not re-initialize, I'm closing as "not a bug". Sorry, Kevin. |
Actually, the refcount bug is still a bug. |
Possible solutions:
What is more preferable? |
Do #1. --Guido (mobile)
|
Here is a patch. |
super_init_leaks.patch LGTM, it fixes. I confirm that the patch fixes the refleak. I checked with: $ ./python -m test -R 3:3 test_super |
Added more comments as suggested by Guido. |
super_init_leaks_2.patch LGTM. |
New changeset 450f36750cb9 by Serhiy Storchaka in branch '3.5': New changeset 4680438f486f by Serhiy Storchaka in branch '2.7': New changeset 55f4c1f8ca6a by Serhiy Storchaka in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: