diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-06-23 01:53:03 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-06-23 01:53:03 -0700 |
| commit | efc6bf66a58e96c12116d65984ac69b0f36f85de (patch) | |
| tree | df31dfa7e17694f4bdeab5847e11b5c8ebf89e7e | |
| parent | f47d8983fe35239cccf4e623e4ad70c9e0f636f9 (diff) | |
| download | cpython-git-efc6bf66a58e96c12116d65984ac69b0f36f85de.tar.gz | |
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.
(cherry picked from commit 9b7cf757213cf4d7ae1d436d86ad53f5ba362d55)
Co-authored-by: Victor Stinner <vstinner@redhat.com>
| -rw-r--r-- | Misc/NEWS.d/next/Library/2018-06-21-11-35-47.bpo-33916.cZgPCD.rst | 2 | ||||
| -rw-r--r-- | Modules/_bz2module.c | 8 | ||||
| -rw-r--r-- | Modules/_lzmamodule.c | 8 |
3 files changed, 14 insertions, 4 deletions
diff --git a/Misc/NEWS.d/next/Library/2018-06-21-11-35-47.bpo-33916.cZgPCD.rst b/Misc/NEWS.d/next/Library/2018-06-21-11-35-47.bpo-33916.cZgPCD.rst new file mode 100644 index 0000000000..65b9d2bf89 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-06-21-11-35-47.bpo-33916.cZgPCD.rst @@ -0,0 +1,2 @@ +bz2 and lzma: When Decompressor.__init__() is called twice, free the old +lock to not leak memory. diff --git a/Modules/_bz2module.c b/Modules/_bz2module.c index 0789b6179e..3890b60b1b 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; diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c index 5bcd088d77..7b501d8202 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; |
