Commit 9b7cf757 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

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.
parent 44742e94
bz2 and lzma: When Decompressor.__init__() is called twice, free the old
lock to not leak memory.
...@@ -634,11 +634,15 @@ _bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self) ...@@ -634,11 +634,15 @@ _bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self)
{ {
int bzerror; int bzerror;
self->lock = PyThread_allocate_lock(); PyThread_type_lock lock = PyThread_allocate_lock();
if (self->lock == NULL) { if (lock == NULL) {
PyErr_SetString(PyExc_MemoryError, "Unable to allocate lock"); PyErr_SetString(PyExc_MemoryError, "Unable to allocate lock");
return -1; return -1;
} }
if (self->lock != NULL) {
PyThread_free_lock(self->lock);
}
self->lock = lock;
self->needs_input = 1; self->needs_input = 1;
self->bzs_avail_in_real = 0; self->bzs_avail_in_real = 0;
......
...@@ -1163,11 +1163,15 @@ _lzma_LZMADecompressor___init___impl(Decompressor *self, int format, ...@@ -1163,11 +1163,15 @@ _lzma_LZMADecompressor___init___impl(Decompressor *self, int format,
self->lzs.allocator = &self->alloc; self->lzs.allocator = &self->alloc;
self->lzs.next_in = NULL; self->lzs.next_in = NULL;
self->lock = PyThread_allocate_lock(); PyThread_type_lock lock = PyThread_allocate_lock();
if (self->lock == NULL) { if (lock == NULL) {
PyErr_SetString(PyExc_MemoryError, "Unable to allocate lock"); PyErr_SetString(PyExc_MemoryError, "Unable to allocate lock");
return -1; return -1;
} }
if (self->lock != NULL) {
PyThread_free_lock(self->lock);
}
self->lock = lock;
self->check = LZMA_CHECK_UNKNOWN; self->check = LZMA_CHECK_UNKNOWN;
self->needs_input = 1; self->needs_input = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment