Skip to content

[3.6] bpo-33916: Fix bz2 and lzma init when called twice (GH-7843) #7872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bz2 and lzma: When Decompressor.__init__() is called twice, free the old
lock to not leak memory.
8 changes: 6 additions & 2 deletions Modules/_bz2module.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,11 +652,15 @@ _bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self)
int bzerror;

#ifdef WITH_THREAD
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;
#endif

self->needs_input = 1;
Expand Down
8 changes: 6 additions & 2 deletions Modules/_lzmamodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1181,11 +1181,15 @@ _lzma_LZMADecompressor___init___impl(Decompressor *self, int format,
self->lzs.next_in = NULL;

#ifdef WITH_THREAD
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;
#endif

self->check = LZMA_CHECK_UNKNOWN;
Expand Down