From 85004cc47d807579a475da9f4367a62eb2fd72a2 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 5 Aug 2003 11:23:59 +0000 Subject: [PATCH] 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. --- Modules/arraymodule.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index f730915151..228c8f4c69 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -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 (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 = -- 2.50.1