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.

Author vstinner
Recipients vstinner
Date 2017-06-09.16:08:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1497024518.09.0.17582224223.issue30614@psf.upfronthosting.co.za>
In-reply-to
Content
The leaking unit test was added to fix a bug found by fuzzing: see bpo-19878.

To fix the bug, I suggest to:

1) Add a clear method: extract most of BZ2File_dealloc() code except of code to clear the lock and the tp_free. Create a new BZ2File_clear() function which clears the file and buffers. Call BZ2File_clear() in BZ2File_dealloc(), but *before* destroying the lock (see later for the rationale). Replace Py_XDECREF(self->file) with Py_CLEAR(self->file). Add ACQUIRE_LOCK/RELEASE_LOCK in BZ2File_clear.

2) Maybe declare BZ2File_clear() as tp_clear. In this case, change BZ2File_clear() return type from void to int, and add "return 0" at the end

3) Move the lock initialization before "self->file = PyObject_CallFunction(...)" in BZ2File_init(). Modify the code to not create the lock twice: if the lock was already created by a previous call to BZ2File_init(), do nothing.

4) Call BZ2File_clear() in BZ2File_init() after the initialization of the lock
History
Date User Action Args
2017-06-09 16:08:38vstinnersetrecipients: + vstinner
2017-06-09 16:08:38vstinnersetmessageid: <1497024518.09.0.17582224223.issue30614@psf.upfronthosting.co.za>
2017-06-09 16:08:38vstinnerlinkissue30614 messages
2017-06-09 16:08:37vstinnercreate