From: Antoine Pitrou Date: Sun, 1 Apr 2012 14:05:46 +0000 (+0200) Subject: Issue #13019: Fix potential reference leaks in bytearray.extend(). X-Git-Tag: v2.7.4rc1~929 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fe9417726c8d2a15ae11f553ae521c3ba6dfc6b7;p=python Issue #13019: Fix potential reference leaks in bytearray.extend(). Patch by Suman Saha. --- diff --git a/Misc/NEWS b/Misc/NEWS index 9c848e44c2..15c943c1c0 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -9,6 +9,9 @@ What's New in Python 2.7.4 Core and Builtins ----------------- +- Issue #13019: Fix potential reference leaks in bytearray.extend(). Patch + by Suman Saha. + - Issue #14378: Fix compiling ast.ImportFrom nodes with a "__future__" string as the module name that was not interned. diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index a40c0ab7ff..03604633a0 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -2296,8 +2296,10 @@ bytearray_extend(PyByteArrayObject *self, PyObject *arg) } bytearray_obj = PyByteArray_FromStringAndSize(NULL, buf_size); - if (bytearray_obj == NULL) + if (bytearray_obj == NULL) { + Py_DECREF(it); return NULL; + } buf = PyByteArray_AS_STRING(bytearray_obj); while ((item = PyIter_Next(it)) != NULL) { @@ -2330,8 +2332,10 @@ bytearray_extend(PyByteArrayObject *self, PyObject *arg) return NULL; } - if (bytearray_setslice(self, Py_SIZE(self), Py_SIZE(self), bytearray_obj) == -1) + if (bytearray_setslice(self, Py_SIZE(self), Py_SIZE(self), bytearray_obj) == -1) { + Py_DECREF(bytearray_obj); return NULL; + } Py_DECREF(bytearray_obj); Py_RETURN_NONE;