Skip to content

Commit

Permalink
compressor: fix memory leak in copy_stream()
Browse files Browse the repository at this point in the history
The PyObject holding the result of the read() operation never
had its refcount decreased. This created a leak.

Fixes #40.
  • Loading branch information
indygreg committed Feb 12, 2018
1 parent 7c6f6ef commit 2a3ca48
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Version History
===============

0.8.2 (released 2018-02-22)
---------------------------

* Fixed memory leak in ``ZstdCompressor.copy_stream()`` (#40).

0.8.1 (released 2017-04-08)
---------------------------

Expand Down
6 changes: 5 additions & 1 deletion c-ext/compressor.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ static PyObject* ZstdCompressor_copy_stream(ZstdCompressor* self, PyObject* args
Py_ssize_t totalWrite = 0;
char* readBuffer;
Py_ssize_t readSize;
PyObject* readResult;
PyObject* readResult = NULL;
PyObject* res = NULL;
size_t zresult;
PyObject* writeResult;
Expand Down Expand Up @@ -410,6 +410,8 @@ static PyObject* ZstdCompressor_copy_stream(ZstdCompressor* self, PyObject* args
output.pos = 0;
}
}

Py_CLEAR(readResult);
}

/* We've finished reading. Now flush the compressor stream. */
Expand Down Expand Up @@ -455,6 +457,8 @@ static PyObject* ZstdCompressor_copy_stream(ZstdCompressor* self, PyObject* args
PyMem_Free(output.dst);
}

Py_XDECREF(readResult);

return res;
}

Expand Down

0 comments on commit 2a3ca48

Please sign in to comment.