summaryrefslogtreecommitdiffstats
path: root/Modules/_bz2module.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/_bz2module.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/_bz2module.c')
-rw-r--r--Modules/_bz2module.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Modules/_bz2module.c b/Modules/_bz2module.c
index 0789b61..3890b60 100644
--- a/Modules/_bz2module.c
+++ b/Modules/_bz2module.c
@@ -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;