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:
parent
44742e94c8
commit
9b7cf75721
|
@ -0,0 +1,2 @@
|
|||
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)
|
|||
{
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue