Issue 31723: refleaks in zipimport when calling zipimporter.init() more than once (original) (raw)

Created on 2017-10-07 15:27 by Oren Milman, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3919 merged Oren Milman,2017-10-07 16:35
Messages (6)
msg303883 - (view) Author: Oren Milman (Oren Milman) * Date: 2017-10-07 15:27
The following code causes refleaks: import zipimport zi = zipimport.zipimporter.__new__(zipimport.zipimporter) zi.__init__('bar.zip') zi.__init__('bar.zip') zi.__init__('bar.zip\\foo') This is because zipimport_zipimporter___init___impl() (in Modules/zipimport.c) doesn't decref (if needed) before assigning to `self->files`, `self->archive` and `self->prefix`. I would open a PR to fix this soon. Should i add a test to test_zipimport? If yes, could you point out some similar refcount test to help me write this test?
msg303969 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-10-09 15:06
New changeset c0cabc23bbe474d542ff8a4f1243f4ec3cce5549 by Victor Stinner (Oren Milman) in branch 'master': bpo-31723: Fix refleaks when zipimporter.__init__() is called more than once (GH-3919) https://github.com/python/cpython/commit/c0cabc23bbe474d542ff8a4f1243f4ec3cce5549
msg303970 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-10-09 15:07
> The following code causes refleaks: I'm curious, how did you find this code? Are you using a code generator coupled with a tool to track for reference leaks?
msg303971 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-10-09 15:08
I merged your PR, thanks! As I wrote on the PR: I don't think that a NEWS entry is needed, since you are not supposed to call __init__() multiple times. I don't think that it's worth it to backport the fix to Python 2.7 and 3.6. So I close the issue.
msg303972 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-10-09 15:09
> I'm curious, how did you find this code? Are you using a code generator coupled with a tool to track for reference leaks? Oh, I think that the issue is related to bpo-31718.
msg303973 - (view) Author: Oren Milman (Oren Milman) * Date: 2017-10-09 15:14
Yes, i am going manually over the code to find similar stuff to #31718, and i afraid i found quite a few, and still working on it..
History
Date User Action Args
2022-04-11 14:58:53 admin set github: 75904
2017-10-09 15:14:07 Oren Milman set messages: +
2017-10-09 15:09:55 vstinner set messages: +
2017-10-09 15:08:00 vstinner set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2017-10-09 15:07:07 vstinner set messages: +
2017-10-09 15:06:21 vstinner set nosy: + vstinnermessages: +
2017-10-07 16:35:00 Oren Milman set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest3892>
2017-10-07 15:27:27 Oren Milman create