Skip to content

Commit

Permalink
decompressor: fix memory leak in copy_stream
Browse files Browse the repository at this point in the history
Fixes #35.
  • Loading branch information
indygreg committed Feb 12, 2018
1 parent 1ca301a commit b461414
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
---------------------------
Expand Down
6 changes: 5 additions & 1 deletion c-ext/decompressor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand All @@ -267,6 +269,8 @@ static PyObject* Decompressor_copy_stream(ZstdDecompressor* self, PyObject* args
PyMem_Free(output.dst);
}

Py_XDECREF(readResult);

return res;
}

Expand Down

0 comments on commit b461414

Please sign in to comment.