]> granicus.if.org Git - python/commitdiff
Issue #13019: Fix potential reference leaks in bytearray.extend().
authorAntoine Pitrou <solipsis@pitrou.net>
Sun, 1 Apr 2012 14:05:46 +0000 (16:05 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Sun, 1 Apr 2012 14:05:46 +0000 (16:05 +0200)
Patch by Suman Saha.

Misc/NEWS
Objects/bytearrayobject.c

index 32c0b9edc4292f342aa1f5cfff8d36988745dae8..4bf3a916b6ba74625af71712b0c75bcafff3bcc5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.2.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.
 
index 4202ff28e44b08e55fe3b6c4b73786e99d37de8a..55b4df638a8509b5af048d328104c1a4addde070 100644 (file)
@@ -2234,8 +2234,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) {
@@ -2268,8 +2270,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;