Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 58bb82e

Browse files
committed
Issue #13019: Fix potential reference leaks in bytearray.extend().
Patch by Suman Saha.
1 parent 165a2c2 commit 58bb82e

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #13019: Fix potential reference leaks in bytearray.extend(). Patch
14+
by Suman Saha.
15+
1316
- Issue #14378: Fix compiling ast.ImportFrom nodes with a "__future__" string as
1417
the module name that was not interned.
1518

Objects/bytearrayobject.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,8 +2234,10 @@ bytearray_extend(PyByteArrayObject *self, PyObject *arg)
22342234
}
22352235

22362236
bytearray_obj = PyByteArray_FromStringAndSize(NULL, buf_size);
2237-
if (bytearray_obj == NULL)
2237+
if (bytearray_obj == NULL) {
2238+
Py_DECREF(it);
22382239
return NULL;
2240+
}
22392241
buf = PyByteArray_AS_STRING(bytearray_obj);
22402242

22412243
while ((item = PyIter_Next(it)) != NULL) {
@@ -2268,8 +2270,10 @@ bytearray_extend(PyByteArrayObject *self, PyObject *arg)
22682270
return NULL;
22692271
}
22702272

2271-
if (bytearray_setslice(self, Py_SIZE(self), Py_SIZE(self), bytearray_obj) == -1)
2273+
if (bytearray_setslice(self, Py_SIZE(self), Py_SIZE(self), bytearray_obj) == -1) {
2274+
Py_DECREF(bytearray_obj);
22722275
return NULL;
2276+
}
22732277
Py_DECREF(bytearray_obj);
22742278

22752279
Py_RETURN_NONE;

0 commit comments

Comments
 (0)