Skip to content

bpo-30614: testInitNonExistentFile() of test_bz2 leaks references #2033

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

Merged
merged 2 commits into from
Jun 10, 2017

Conversation

matrixise
Copy link
Member

Extract the code of BZ2File_dealloc and create a new BZ2File_clear()
function. Call BZ2File_clear() in BZ2File_dealloc().

Define BZ2File_clear() as tp_clear.

Move the lock initialization before the "self->file =
PyObject_CallFunction" in BZ2File_init() and check the lock is not
created twice.

Call BZ2File_clear() in BZ2File_init() after the init of the lock

Co-Authored-By: Victor Stinner victor.stinner@gmail.com

Extract the code of BZ2File_dealloc and create a new BZ2File_clear()
function. Call BZ2File_clear() in BZ2File_dealloc().

Define BZ2File_clear() as tp_clear.

Move the lock initialization before the "self->file =
PyObject_CallFunction" in BZ2File_init() and check the lock is not
created twice.

Call BZ2File_clear() in BZ2File_init() after the init of the lock

Co-Authored-By: Victor Stinner <victor.stinner@gmail.com>
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice work. I just have minor requests.

@@ -1420,6 +1444,18 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs)

mode = (mode_char == 'r') ? "rb" : "wb";

#ifdef WITH_THREAD
if (!self->lock)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put the following code in the conditional if: { ... }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, you can add the following comment:

/* if init is called twice, keep the existing lock */

Fix after the review of Victor Stinner
@matrixise
Copy link
Member Author

Done, could you review it again ? thanks

@vstinner vstinner merged commit 28288be into python:2.7 Jun 10, 2017
@vstinner
Copy link
Member

Thanks @matrixise for your fix ;-)

@matrixise
Copy link
Member Author

Welcome ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants