bz2, lzma: When Decompressor.__init__() is called twice, free the old
lock to not leak memory.
--- /dev/null
+bz2 and lzma: When Decompressor.__init__() is called twice, free the old
+lock to not leak memory.
{
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;
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;