SF bug #782369: Massive memory leak in array module

Fixed leak caused by switching from PyList_GetItem to PySequence_GetItem.
Added missing NULL check.
Clarified code by converting an "if" to an "else if".

Will backport to 2.3.
This commit is contained in:
Raymond Hettinger 2003-08-05 11:23:59 +00:00
parent 83f5291c0f
commit 85004cc47d
1 changed files with 8 additions and 3 deletions

View File

@ -1758,13 +1758,18 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
for (i = 0; i < len; i++) {
PyObject *v =
PySequence_GetItem(initial, i);
if (setarrayitem(a, i, v) != 0) {
if (v == NULL) {
Py_DECREF(a);
return NULL;
}
if (setarrayitem(a, i, v) != 0) {
Py_DECREF(v);
Py_DECREF(a);
return NULL;
}
Py_DECREF(v);
}
}
if (initial != NULL && PyString_Check(initial)) {
} else if (initial != NULL && PyString_Check(initial)) {
PyObject *t_initial = Py_BuildValue("(O)",
initial);
PyObject *v =