diff options
Diffstat (limited to 'Modules/zlibmodule.c')
-rw-r--r-- | Modules/zlibmodule.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index fa07739a16..969db4aa4d 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -116,7 +116,7 @@ PyZlib_compress(PyObject *self, PyObject *args) { PyObject *ReturnVal = NULL; Py_buffer pinput; - Byte *input, *output = NULL; + Byte *input, *output; unsigned int length; int level=Z_DEFAULT_COMPRESSION, err; z_stream zst; @@ -127,19 +127,20 @@ PyZlib_compress(PyObject *self, PyObject *args) if (pinput.len > UINT_MAX) { PyErr_SetString(PyExc_OverflowError, - "Size does not fit in an unsigned int"); - goto error; + "size does not fit in an unsigned int"); + return NULL; } - input = pinput.buf; length = pinput.len; + input = pinput.buf; zst.avail_out = length + length/1000 + 12 + 1; output = (Byte*)malloc(zst.avail_out); if (output == NULL) { + PyBuffer_Release(&pinput); PyErr_SetString(PyExc_MemoryError, "Can't allocate memory to compress data"); - goto error; + return NULL; } /* Past the point of no return. From here on out, we need to make sure @@ -202,7 +203,7 @@ PyDoc_STRVAR(decompress__doc__, static PyObject * PyZlib_decompress(PyObject *self, PyObject *args) { - PyObject *result_str = NULL; + PyObject *result_str; Py_buffer pinput; Byte *input; unsigned int length; @@ -217,11 +218,11 @@ PyZlib_decompress(PyObject *self, PyObject *args) if (pinput.len > UINT_MAX) { PyErr_SetString(PyExc_OverflowError, - "Size does not fit in an unsigned int"); - goto error; + "size does not fit in an unsigned int"); + return NULL; } - input = pinput.buf; length = pinput.len; + input = pinput.buf; if (r_strlen <= 0) r_strlen = 1; @@ -229,8 +230,10 @@ PyZlib_decompress(PyObject *self, PyObject *args) zst.avail_in = length; zst.avail_out = r_strlen; - if (!(result_str = PyBytes_FromStringAndSize(NULL, r_strlen))) - goto error; + if (!(result_str = PyBytes_FromStringAndSize(NULL, r_strlen))) { + PyBuffer_Release(&pinput); + return NULL; + } zst.zalloc = (alloc_func)NULL; zst.zfree = (free_func)Z_NULL; |