diff options
author | Raymond Hettinger <python@rcn.com> | 2003-08-06 06:55:09 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-08-06 06:55:09 (GMT) |
commit | dc72e5683ed2df8004077842b51efc72a8f54307 (patch) | |
tree | 68d534d0fb552116934ef518e070a1b628f877e6 /Modules/arraymodule.c | |
parent | 3efb725b1c01c4bd838b19fbc20934fc203f235a (diff) | |
download | cpython-dc72e5683ed2df8004077842b51efc72a8f54307.zip cpython-dc72e5683ed2df8004077842b51efc72a8f54307.tar.gz cpython-dc72e5683ed2df8004077842b51efc72a8f54307.tar.bz2 |
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".
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r-- | Modules/arraymodule.c | 9 |
1 files changed, 7 insertions, 2 deletions
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 = |