From 4ebd46a02d7ab56b1398d7e5393dd32dc26becac Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Thu, 27 Mar 2008 04:40:07 +0000 Subject: [PATCH] Fix memory leaks --- Objects/bytesobject.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 90990a744cb..23de37e07a9 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2683,17 +2683,21 @@ bytes_extend(PyBytesObject *self, PyObject *arg) if (! _getbytevalue(item, &value)) { Py_DECREF(item); Py_DECREF(it); + PyMem_Free(buf); return NULL; } buf[len++] = value; Py_DECREF(item); if (len >= buf_size) { + char *new_buf; buf_size = len + (len >> 1) + 1; - buf = (char *)PyMem_Realloc(buf, buf_size * sizeof(char)); - if (buf == NULL) { + new_buf = (char *)PyMem_Realloc(buf, buf_size * sizeof(char)); + if (new_buf == NULL) { Py_DECREF(it); + PyMem_Free(buf); return PyErr_NoMemory(); } + buf = new_buf; } } Py_DECREF(it);