diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -644,7 +644,7 @@ fileio_readall(fileio *self) if (PyBytes_GET_SIZE(result) < (Py_ssize_t)newsize) { if (_PyBytes_Resize(&result, newsize) < 0) { if (total == 0) { - Py_DECREF(result); + Py_CLEAR(result); return NULL; } PyErr_Clear(); @@ -695,7 +695,7 @@ fileio_readall(fileio *self) if (PyBytes_GET_SIZE(result) > total) { if (_PyBytes_Resize(&result, total) < 0) { /* This should never happen, but just in case */ - Py_DECREF(result); + Py_CLEAR(result); return NULL; } } @@ -755,7 +755,7 @@ fileio_read(fileio *self, PyObject *args if (n != size) { if (_PyBytes_Resize(&bytes, n) < 0) { - Py_DECREF(bytes); + Py_CLEAR(bytes); return NULL; } } diff --git a/Modules/binascii.c b/Modules/binascii.c --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -361,8 +361,7 @@ binascii_b2a_uu(PyObject *self, PyObject if (_PyBytes_Resize(&rv, (ascii_data - (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { - Py_DECREF(rv); - rv = NULL; + Py_CLEAR(rv); } PyBuffer_Release(&pbin); return rv; @@ -491,8 +490,7 @@ binascii_a2b_base64(PyObject *self, PyOb */ if (bin_len > 0) { if (_PyBytes_Resize(&rv, bin_len) < 0) { - Py_DECREF(rv); - rv = NULL; + Py_CLEAR(rv); } } else { @@ -563,8 +561,7 @@ binascii_b2a_base64(PyObject *self, PyOb if (_PyBytes_Resize(&rv, (ascii_data - (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { - Py_DECREF(rv); - rv = NULL; + Py_CLEAR(rv); } PyBuffer_Release(&pbuf); return rv; @@ -642,8 +639,7 @@ binascii_a2b_hqx(PyObject *self, PyObjec if (_PyBytes_Resize(&rv, (bin_data - (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { - Py_DECREF(rv); - rv = NULL; + Py_CLEAR(rv); } if (rv) { PyObject *rrv = Py_BuildValue("Oi", rv, done); @@ -713,8 +709,7 @@ binascii_rlecode_hqx(PyObject *self, PyO if (_PyBytes_Resize(&rv, (out_data - (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { - Py_DECREF(rv); - rv = NULL; + Py_CLEAR(rv); } PyBuffer_Release(&pbuf); return rv; @@ -770,8 +765,7 @@ binascii_b2a_hqx(PyObject *self, PyObjec if (_PyBytes_Resize(&rv, (ascii_data - (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { - Py_DECREF(rv); - rv = NULL; + Py_CLEAR(rv); } PyBuffer_Release(&pbin); return rv; @@ -834,7 +828,7 @@ binascii_rledecode_hqx(PyObject *self, P if ( --out_len_left < 0 ) { \ if ( out_len > PY_SSIZE_T_MAX / 2) return PyErr_NoMemory(); \ if (_PyBytes_Resize(&rv, 2*out_len) < 0) \ - { Py_DECREF(rv); PyBuffer_Release(&pin); return NULL; } \ + { Py_CLEAR(rv); PyBuffer_Release(&pin); return NULL; } \ out_data = (unsigned char *)PyBytes_AS_STRING(rv) \ + out_len; \ out_len_left = out_len-1; \ @@ -887,8 +881,7 @@ binascii_rledecode_hqx(PyObject *self, P if (_PyBytes_Resize(&rv, (out_data - (unsigned char *)PyBytes_AS_STRING(rv))) < 0) { - Py_DECREF(rv); - rv = NULL; + Py_CLEAR(rv); } PyBuffer_Release(&pin); return rv; diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -698,10 +698,10 @@ PyZlib_objdecompress(compobject *self, P length = max_length; if (_PyBytes_Resize(&RetVal, length) < 0) { - Py_DECREF(RetVal); - RetVal = NULL; + Py_CLEAR(RetVal); goto error; } + self->zst.next_out = (unsigned char *)PyBytes_AS_STRING(RetVal) + old_length; self->zst.avail_out = length - old_length; @@ -733,8 +733,7 @@ PyZlib_objdecompress(compobject *self, P } if (_PyBytes_Resize(&RetVal, self->zst.total_out - start_total_out) < 0) { - Py_DECREF(RetVal); - RetVal = NULL; + Py_CLEAR(RetVal); } error: @@ -787,8 +786,7 @@ PyZlib_flush(compobject *self, PyObject so extend the output buffer and try again */ while (err == Z_OK && self->zst.avail_out == 0) { if (_PyBytes_Resize(&RetVal, length << 1) < 0) { - Py_DECREF(RetVal); - RetVal = NULL; + Py_CLEAR(RetVal); goto error; } self->zst.next_out = @@ -827,8 +825,7 @@ PyZlib_flush(compobject *self, PyObject } if (_PyBytes_Resize(&RetVal, self->zst.total_out - start_total_out) < 0) { - Py_DECREF(RetVal); - RetVal = NULL; + Py_CLEAR(RetVal); } error: @@ -988,8 +985,7 @@ PyZlib_unflush(compobject *self, PyObjec so extend the output buffer and try again */ while ((err == Z_OK || err == Z_BUF_ERROR) && self->zst.avail_out == 0) { if (_PyBytes_Resize(&retval, length << 1) < 0) { - Py_DECREF(retval); - retval = NULL; + Py_CLEAR(retval); goto error; } self->zst.next_out = (Byte *)PyBytes_AS_STRING(retval) + length; @@ -1021,8 +1017,7 @@ PyZlib_unflush(compobject *self, PyObjec } if (_PyBytes_Resize(&retval, self->zst.total_out - start_total_out) < 0) { - Py_DECREF(retval); - retval = NULL; + Py_CLEAR(retval); } error: