[Python-checkins] cpython (merge 3.2 -> default): Issue #13019: Fix potential reference leaks in bytearray.extend().

antoine.pitrou python-checkins at python.org
Sun Apr 1 16:14:43 CEST 2012


http://hg.python.org/cpython/rev/015c546615ca
changeset: 76048:015c546615ca
parent: 76046:90bc4b367fcb
parent: 76047:03396c9ffe8c
user: Antoine Pitrou <solipsis at pitrou.net>
date: Sun Apr 01 16:08:11 2012 +0200
summary:
 Issue #13019: Fix potential reference leaks in bytearray.extend().
Patch by Suman Saha.
files:
 Misc/NEWS | 3 +++
 Objects/bytearrayobject.c | 8 ++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #13019: Fix potential reference leaks in bytearray.extend(). Patch
+ by Suman Saha.
+
 - Issue #1683368: object.__new__ and object.__init__ raise a TypeError if they
 are passed arguments and their complementary method is not overridden.
 
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -2289,8 +2289,10 @@
 }
 
 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) {
@@ -2323,8 +2325,10 @@
 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;
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /