summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-08-05 11:23:59 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-08-05 11:23:59 (GMT)
commit85004cc47d807579a475da9f4367a62eb2fd72a2 (patch)
tree0d0ad248efef389901dde7c76e98f605c212f1d8
parent83f5291c0fa282ef01156e7bee0c62a231a3dfda (diff)
downloadcpython-85004cc47d807579a475da9f4367a62eb2fd72a2.zip
cpython-85004cc47d807579a475da9f4367a62eb2fd72a2.tar.gz
cpython-85004cc47d807579a475da9f4367a62eb2fd72a2.tar.bz2
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.
-rw-r--r--Modules/arraymodule.c9
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 =