From dc72e5683ed2df8004077842b51efc72a8f54307 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Wed, 6 Aug 2003 06:55:09 +0000 Subject: Backport 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". --- Misc/NEWS | 2 ++ Modules/arraymodule.c | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index d46a5e2..45bf3e5 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -24,6 +24,8 @@ Library - Bug #781065: test_normalization is updated to the current URL of the Unicode 3.2 normalization file. +- Bug #782369: fix memory leak in array module. + IDLE ---- diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index f730915..228c8f4 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 = -- cgit v0.12