Message295549
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 |
|
Date |
User |
Action |
Args |
2017-06-09 16:08:38 | vstinner | set | recipients:
+ vstinner |
2017-06-09 16:08:38 | vstinner | set | messageid: <1497024518.09.0.17582224223.issue30614@psf.upfronthosting.co.za> |
2017-06-09 16:08:38 | vstinner | link | issue30614 messages |
2017-06-09 16:08:37 | vstinner | create | |
|