Commit 4ebd46a0 authored by Neal Norwitz's avatar Neal Norwitz

Fix memory leaks

parent 0bcd613e
...@@ -2683,17 +2683,21 @@ bytes_extend(PyBytesObject *self, PyObject *arg) ...@@ -2683,17 +2683,21 @@ bytes_extend(PyBytesObject *self, PyObject *arg)
if (! _getbytevalue(item, &value)) { if (! _getbytevalue(item, &value)) {
Py_DECREF(item); Py_DECREF(item);
Py_DECREF(it); Py_DECREF(it);
PyMem_Free(buf);
return NULL; return NULL;
} }
buf[len++] = value; buf[len++] = value;
Py_DECREF(item); Py_DECREF(item);
if (len >= buf_size) { if (len >= buf_size) {
char *new_buf;
buf_size = len + (len >> 1) + 1; buf_size = len + (len >> 1) + 1;
buf = (char *)PyMem_Realloc(buf, buf_size * sizeof(char)); new_buf = (char *)PyMem_Realloc(buf, buf_size * sizeof(char));
if (buf == NULL) { if (new_buf == NULL) {
Py_DECREF(it); Py_DECREF(it);
PyMem_Free(buf);
return PyErr_NoMemory(); return PyErr_NoMemory();
} }
buf = new_buf;
} }
} }
Py_DECREF(it); Py_DECREF(it);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment