diff --git a/NEWS.rst b/NEWS.rst index 521485b9..83f07bb3 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -5,6 +5,7 @@ Version History --------------------------- * Fixed memory leak in ``ZstdCompressor.copy_stream()`` (#40). +* Fixed memory leak in ``ZstdDecompressor.copy_stream()`` (#35). 0.8.1 (released 2017-04-08) --------------------------- diff --git a/c-ext/decompressor.c b/c-ext/decompressor.c index c3dc2922..4ad8a028 100644 --- a/c-ext/decompressor.c +++ b/c-ext/decompressor.c @@ -166,7 +166,7 @@ static PyObject* Decompressor_copy_stream(ZstdDecompressor* 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 = 0; PyObject* writeResult; @@ -252,6 +252,8 @@ static PyObject* Decompressor_copy_stream(ZstdDecompressor* self, PyObject* args output.pos = 0; } } + + Py_CLEAR(readResult); } /* Source stream is exhausted. Finish up. */ @@ -267,6 +269,8 @@ static PyObject* Decompressor_copy_stream(ZstdDecompressor* self, PyObject* args PyMem_Free(output.dst); } + Py_XDECREF(readResult); + return res; }