summaryrefslogtreecommitdiffstats
path: root/Modules/_lzmamodule.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-06-23 08:35:23 (GMT)
committerGitHub <noreply@github.com>2018-06-23 08:35:23 (GMT)
commit9b7cf757213cf4d7ae1d436d86ad53f5ba362d55 (patch)
tree142983943c87abd96321b5ec83873c8a16fda1bf /Modules/_lzmamodule.c
parent44742e94c809d580fa406f9d21b86e1d4e1938a5 (diff)
downloadcpython-9b7cf757213cf4d7ae1d436d86ad53f5ba362d55.zip
cpython-9b7cf757213cf4d7ae1d436d86ad53f5ba362d55.tar.gz
cpython-9b7cf757213cf4d7ae1d436d86ad53f5ba362d55.tar.bz2
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.
Diffstat (limited to 'Modules/_lzmamodule.c')
-rw-r--r--Modules/_lzmamodule.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c
index 5bcd088..7b501d8 100644
--- a/Modules/_lzmamodule.c
+++ b/Modules/_lzmamodule.c
@@ -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;