Mercurial > cpython-lru_cache-weakref
diff Modules/arraymodule.c @ 30066:ae0242e3459e legacy-trunk
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.
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Tue, 05 Aug 2003 11:23:59 +0000 |
| parents | 23ad8b5d7b4a |
| children | 88c1e17ceffc 3b59fa5d25b1 |
line wrap: on
line diff
--- a/Modules/arraymodule.c Tue Aug 05 06:33:56 2003 +0000 +++ b/Modules/arraymodule.c Tue Aug 05 11:23:59 2003 +0000 @@ -1758,13 +1758,18 @@ 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 =
