]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport SF bug #782369: Massive memory leak in array module
authorRaymond Hettinger <python@rcn.com>
Wed, 6 Aug 2003 06:55:09 +0000 (06:55 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 6 Aug 2003 06:55:09 +0000 (06:55 +0000)
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
Modules/arraymodule.c

index d46a5e20df393d50331fb4e3282aa7e166ffe5aa..45bf3e5cb631d3a5205759acbd8c9f59135c21ab 100644 (file)
--- 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
 ----
 
index f730915151add782fd4d4728eaa1d6209c2c8d7a..228c8f4c6989a31ca08cb8f6db74ce40a31dbf43 100644 (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 (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 =