diff -r 4a3b455abf76 Modules/_io/fileio.c --- a/Modules/_io/fileio.c Wed Apr 09 15:40:18 2014 -0400 +++ b/Modules/_io/fileio.c Thu Apr 17 16:54:41 2014 +0000 @@ -549,14 +549,8 @@ } if (PyBytes_GET_SIZE(result) < (Py_ssize_t)newsize) { - if (_PyBytes_Resize(&result, newsize) < 0) { - if (total == 0) { - Py_DECREF(result); - return NULL; - } - PyErr_Clear(); - break; - } + if (_PyBytes_Resize(&result, newsize) < 0) + return NULL; /* result has been freed */ } Py_BEGIN_ALLOW_THREADS errno = 0; @@ -599,7 +593,6 @@ if (PyBytes_GET_SIZE(result) > total) { if (_PyBytes_Resize(&result, total) < 0) { /* This should never happen, but just in case */ - Py_DECREF(result); return NULL; } } @@ -656,10 +649,8 @@ } if (n != size) { - if (_PyBytes_Resize(&bytes, n) < 0) { - Py_DECREF(bytes); + if (_PyBytes_Resize(&bytes, n) < 0) return NULL; - } } return (PyObject *) bytes; diff -r 4a3b455abf76 Modules/binascii.c --- a/Modules/binascii.c Wed Apr 09 15:40:18 2014 -0400 +++ b/Modules/binascii.c Thu Apr 17 16:54:41 2014 +0000 @@ -320,12 +320,10 @@ } *ascii_data++ = '\n'; /* Append a courtesy newline */ - if (_PyString_Resize(&rv, + /* rv is cleared on error */ + (void)_PyString_Resize(&rv, (ascii_data - - (unsigned char *)PyString_AS_STRING(rv))) < 0) { - Py_DECREF(rv); - rv = NULL; - } + (unsigned char *)PyString_AS_STRING(rv))); PyBuffer_Release(&pbin); return rv; } @@ -452,10 +450,8 @@ ** string instead; _PyString_Resize() won't do this for us. */ if (bin_len > 0) { - if (_PyString_Resize(&rv, bin_len) < 0) { - Py_DECREF(rv); - rv = NULL; - } + /* rv is cleared on error */ + (void)_PyString_Resize(&rv, bin_len); } else { Py_DECREF(rv); @@ -522,12 +518,10 @@ } *ascii_data++ = '\n'; /* Append a courtesy newline */ - if (_PyString_Resize(&rv, + /* rv is cleared on error */ + (void)_PyString_Resize(&rv, (ascii_data - - (unsigned char *)PyString_AS_STRING(rv))) < 0) { - Py_DECREF(rv); - rv = NULL; - } + (unsigned char *)PyString_AS_STRING(rv))); PyBuffer_Release(&pbuf); return rv; } @@ -601,13 +595,10 @@ Py_DECREF(rv); return NULL; } + /* rv is cleared on error */ if (_PyString_Resize(&rv, (bin_data - - (unsigned char *)PyString_AS_STRING(rv))) < 0) { - Py_DECREF(rv); - rv = NULL; - } - if (rv) { + (unsigned char *)PyString_AS_STRING(rv))) == 0) { PyObject *rrv = Py_BuildValue("Oi", rv, done); PyBuffer_Release(&pascii); Py_DECREF(rv); @@ -672,12 +663,10 @@ } } } - if (_PyString_Resize(&rv, + /* rv is cleared on error */ + (void)_PyString_Resize(&rv, (out_data - - (unsigned char *)PyString_AS_STRING(rv))) < 0) { - Py_DECREF(rv); - rv = NULL; - } + (unsigned char *)PyString_AS_STRING(rv))); PyBuffer_Release(&pbuf); return rv; } @@ -729,12 +718,10 @@ leftchar <<= (6-leftbits); *ascii_data++ = table_b2a_hqx[leftchar & 0x3f]; } - if (_PyString_Resize(&rv, + /* rv is cleared on error */ + (void)_PyString_Resize(&rv, (ascii_data - - (unsigned char *)PyString_AS_STRING(rv))) < 0) { - Py_DECREF(rv); - rv = NULL; - } + (unsigned char *)PyString_AS_STRING(rv))); PyBuffer_Release(&pbin); return rv; } @@ -796,7 +783,7 @@ if ( --out_len_left < 0 ) { \ if ( out_len > PY_SSIZE_T_MAX / 2) return PyErr_NoMemory(); \ if (_PyString_Resize(&rv, 2*out_len) < 0) \ - { Py_DECREF(rv); PyBuffer_Release(&pin); return NULL; } \ + { PyBuffer_Release(&pin); return NULL; } \ out_data = (unsigned char *)PyString_AS_STRING(rv) \ + out_len; \ out_len_left = out_len-1; \ @@ -846,12 +833,10 @@ OUTBYTE(in_byte); } } - if (_PyString_Resize(&rv, + /* rv is cleared on error */ + (void)_PyString_Resize(&rv, (out_data - - (unsigned char *)PyString_AS_STRING(rv))) < 0) { - Py_DECREF(rv); - rv = NULL; - } + (unsigned char *)PyString_AS_STRING(rv))); PyBuffer_Release(&pin); return rv; } diff -r 4a3b455abf76 Modules/bz2module.c --- a/Modules/bz2module.c Wed Apr 09 15:40:18 2014 -0400 +++ b/Modules/bz2module.c Thu Apr 17 16:54:41 2014 +0000 @@ -732,7 +732,8 @@ } else { /* Grow the big buffer */ - _PyString_Resize(&big_buffer, buffersize); + if (_PyString_Resize(&big_buffer, buffersize)) + goto error; buffer = PyString_AS_STRING(big_buffer); } continue; diff -r 4a3b455abf76 Objects/bytearrayobject.c --- a/Objects/bytearrayobject.c Wed Apr 09 15:40:18 2014 -0400 +++ b/Objects/bytearrayobject.c Thu Apr 17 16:54:41 2014 +0000 @@ -994,10 +994,8 @@ *p++ = *quote_postfix++; } *p = '\0'; - if (_PyString_Resize(&v, (p - PyString_AS_STRING(v)))) { - Py_DECREF(v); - return NULL; - } + /* v is cleared on error */ + (void)_PyString_Resize(&v, (p - PyString_AS_STRING(v))); return v; } } diff -r 4a3b455abf76 Objects/stringobject.c --- a/Objects/stringobject.c Wed Apr 09 15:40:18 2014 -0400 +++ b/Objects/stringobject.c Thu Apr 17 16:54:41 2014 +0000 @@ -748,8 +748,8 @@ UTF-8 bytes may follow. */ } } - if (p-buf < newlen && _PyString_Resize(&v, p - buf)) - goto failed; + if (p-buf < newlen) + _PyString_Resize(&v, p - buf); /* v is cleared on error */ return v; failed: Py_DECREF(v); diff -r 4a3b455abf76 PC/_subprocess.c --- a/PC/_subprocess.c Wed Apr 09 15:40:18 2014 -0400 +++ b/PC/_subprocess.c Thu Apr 17 16:54:41 2014 +0000 @@ -367,7 +367,8 @@ vsize + 1 + 1; if (totalsize > PyString_GET_SIZE(out)) { int offset = p - PyString_AS_STRING(out); - _PyString_Resize(&out, totalsize + 1024); + if (_PyString_Resize(&out, totalsize + 1024)) + goto exit; p = PyString_AS_STRING(out) + offset; } memcpy(p, PyString_AS_STRING(key), ksize); @@ -383,7 +384,7 @@ _PyString_Resize(&out, p - PyString_AS_STRING(out)); /* PyObject_Print(out, stdout, 0); */ - +exit: Py_XDECREF(keys); Py_XDECREF(values);