bpo-33916: Fix bz2 and lzma init when called twice (GH-7843)

bz2, lzma: When Decompressor.__init__() is called twice, free the old
lock to not leak memory.
This commit is contained in:
Victor Stinner 2018-06-23 10:35:23 +02:00 committed by GitHub
parent 44742e94c8
commit 9b7cf75721
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View File

@ -0,0 +1,2 @@
bz2 and lzma: When Decompressor.__init__() is called twice, free the old
lock to not leak memory.

View File

@ -634,11 +634,15 @@ _bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self)
{
int bzerror;
self->lock = PyThread_allocate_lock();
if (self->lock == NULL) {
PyThread_type_lock lock = PyThread_allocate_lock();
if (lock == NULL) {
PyErr_SetString(PyExc_MemoryError, "Unable to allocate lock");
return -1;
}
if (self->lock != NULL) {
PyThread_free_lock(self->lock);
}
self->lock = lock;
self->needs_input = 1;
self->bzs_avail_in_real = 0;

View File

@ -1163,11 +1163,15 @@ _lzma_LZMADecompressor___init___impl(Decompressor *self, int format,
self->lzs.allocator = &self->alloc;
self->lzs.next_in = NULL;
self->lock = PyThread_allocate_lock();
if (self->lock == NULL) {
PyThread_type_lock lock = PyThread_allocate_lock();
if (lock == NULL) {
PyErr_SetString(PyExc_MemoryError, "Unable to allocate lock");
return -1;
}
if (self->lock != NULL) {
PyThread_free_lock(self->lock);
}
self->lock = lock;
self->check = LZMA_CHECK_UNKNOWN;
self->needs_input = 1;