summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-09-16 04:27:52 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-09-16 04:27:52 (GMT)
commitcc1798e0c00735ed1dcee8b5f71d94377b501105 (patch)
tree6845d0c2511bd7789ce6926ad9c30c8a33477180 /Python
parentdeb2dc6658b112da80f522a098eb60f339403289 (diff)
downloadcpython-cc1798e0c00735ed1dcee8b5f71d94377b501105.zip
cpython-cc1798e0c00735ed1dcee8b5f71d94377b501105.tar.gz
cpython-cc1798e0c00735ed1dcee8b5f71d94377b501105.tar.bz2
Improve the leak fix so that PyTuple_New is only called when needed.
Diffstat (limited to 'Python')
-rw-r--r--Python/compile.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/Python/compile.c b/Python/compile.c
index f94a3ac..b95732b 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -105,7 +105,7 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kw)
int stacksize;
int flags;
PyObject *co;
- PyObject *empty;
+ PyObject *empty = NULL;
PyObject *code;
PyObject *consts;
PyObject *names;
@@ -135,19 +135,21 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kw)
return NULL;
}
- empty = PyTuple_New(0);
- if (empty == NULL)
- return NULL;
- if (freevars == NULL)
- freevars = empty;
- if (cellvars == NULL)
- cellvars = empty;
+ if (freevars == NULL || cellvars == NULL) {
+ empty = PyTuple_New(0);
+ if (empty == NULL)
+ return NULL;
+ if (freevars == NULL)
+ freevars = empty;
+ if (cellvars == NULL)
+ cellvars = empty;
+ }
co = (PyObject *) PyCode_New(argcount, nlocals, stacksize, flags,
code, consts, names, varnames,
freevars, cellvars, filename, name,
firstlineno, lnotab);
- Py_DECREF(empty);
+ Py_XDECREF(empty);
return co;
}