This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: refleaks in zipimport when calling zipimporter.__init__() more than once
Type: resource usage Stage: resolved
Components: Extension Modules Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Oren Milman, vstinner
Priority: normal Keywords: patch

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:53adminsetgithub: 75904
2017-10-09 15:14:07Oren Milmansetmessages: + msg303973
2017-10-09 15:09:55vstinnersetmessages: + msg303972
2017-10-09 15:08:00vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg303971

stage: patch review -> resolved
2017-10-09 15:07:07vstinnersetmessages: + msg303970
2017-10-09 15:06:21vstinnersetnosy: + vstinner
messages: + msg303969
2017-10-07 16:35:00Oren Milmansetkeywords: + patch
stage: patch review
pull_requests: + pull_request3892
2017-10-07 15:27:27Oren Milmancreate