diff --git a/lz4/block/_block.c b/lz4/block/_block.c index 993cc44..4b7dc38 100644 --- a/lz4/block/_block.c +++ b/lz4/block/_block.c @@ -215,6 +215,8 @@ compress (PyObject * Py_UNUSED (self), PyObject * args, PyObject * kwargs) dest = PyMem_Malloc (total_size * sizeof * dest); if (dest == NULL) { + PyBuffer_Release(&source); + PyBuffer_Release(&dict); return PyErr_NoMemory(); } @@ -349,6 +351,8 @@ decompress (PyObject * Py_UNUSED (self), PyObject * args, PyObject * kwargs) dest = PyMem_Malloc (dest_size * sizeof * dest); if (dest == NULL) { + PyBuffer_Release(&source); + PyBuffer_Release(&dict); return PyErr_NoMemory(); } diff --git a/lz4/frame/_frame.c b/lz4/frame/_frame.c index 440b0b5..eb1c76b 100644 --- a/lz4/frame/_frame.c +++ b/lz4/frame/_frame.c @@ -184,6 +184,7 @@ compress (PyObject * Py_UNUSED (self), PyObject * args, } else if (block_checksum) { + PyBuffer_Release(&source); PyErr_SetString (PyExc_RuntimeError, "block_checksum specified but not supported by LZ4 library version"); return NULL; @@ -383,6 +384,7 @@ compress_begin (PyObject * Py_UNUSED (self), PyObject * args, if (LZ4F_isError (result)) { + PyMem_Free (destination); PyErr_Format (PyExc_RuntimeError, "LZ4F_compressBegin failed with code: %s", LZ4F_getErrorName (result)); @@ -1115,6 +1117,7 @@ __decompress(LZ4F_dctx * context, char * source, size_t source_size, buff = PyMem_Realloc (destination, destination_size); if (buff == NULL) { + PyMem_Free (destination); PyErr_SetString (PyExc_RuntimeError, "Failed to resize buffer"); return NULL; diff --git a/lz4/stream/_stream.c b/lz4/stream/_stream.c index 4c51d89..e92f8a8 100644 --- a/lz4/stream/_stream.c +++ b/lz4/stream/_stream.c @@ -1063,7 +1063,7 @@ _compress_bound (PyObject * Py_UNUSED (self), PyObject * args) /* Positional arguments: input_size * Keyword arguments : none */ - if (!PyArg_ParseTuple (args, "OI", &input_size)) + if (!PyArg_ParseTuple (args, "I", &input_size)) { goto exit_now; } @@ -1211,6 +1211,7 @@ _compress (PyObject * Py_UNUSED (self), PyObject * args) if (context->strategy.ops->update_context_after_process (context) != 0) { + Py_CLEAR (py_dest); PyErr_Format (PyExc_RuntimeError, "Internal error"); goto exit_now; }