diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-07-08 22:35:22 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-07-08 22:35:22 (GMT) |
commit | 79799266165b5d8d4e8b9b007d81ba3b00197ca9 (patch) | |
tree | a79e1d91c4ec128ec35be099de28e7d5817fce52 /Modules/binascii.c | |
parent | e0af3a802a67d3467b18510869ee1cf9d233fe8e (diff) | |
download | cpython-79799266165b5d8d4e8b9b007d81ba3b00197ca9.zip cpython-79799266165b5d8d4e8b9b007d81ba3b00197ca9.tar.gz cpython-79799266165b5d8d4e8b9b007d81ba3b00197ca9.tar.bz2 |
Issue #18408: Fix usage of _PyBytes_Resize()
_PyBytes_Resize(&v, new_size) sets v to NULL on error, so v cannot be used
anymore. Replace "Py_DECREF(v); v = NULL;" with "Py_CLEAR(v);".
Diffstat (limited to 'Modules/binascii.c')
-rw-r--r-- | Modules/binascii.c | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/Modules/binascii.c b/Modules/binascii.c index 340ec9c..386c2de 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -361,8 +361,7 @@ binascii_b2a_uu(PyObject *self, PyObject *args) 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, PyObject *args) */ 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, PyObject *args) 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, PyObject *args) 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, PyObject *args) 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, PyObject *args) 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, PyObject *args) 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_XDECREF(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, PyObject *args) 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; |