diff options
author | Raymond Hettinger <python@rcn.com> | 2003-09-15 21:43:16 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-09-15 21:43:16 (GMT) |
commit | 37a724d718072e0cdb7b9e773a7c0b9461b3eba1 (patch) | |
tree | 38a15199cf0d8b2beff22c7fa367e6e1bd539e17 | |
parent | 1e4cf67c32f3885e07b14a146bc121e422075274 (diff) | |
download | cpython-37a724d718072e0cdb7b9e773a7c0b9461b3eba1.zip cpython-37a724d718072e0cdb7b9e773a7c0b9461b3eba1.tar.gz cpython-37a724d718072e0cdb7b9e773a7c0b9461b3eba1.tar.bz2 |
Fix leak discovered in test_new by Michael Hudson.
Will backport to 2.3.1
-rw-r--r-- | Python/compile.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/Python/compile.c b/Python/compile.c index 69a07af..f94a3ac 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -104,6 +104,8 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kw) int nlocals; int stacksize; int flags; + PyObject *co; + PyObject *empty; PyObject *code; PyObject *consts; PyObject *names; @@ -127,31 +129,26 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kw) &PyTuple_Type, &cellvars)) return NULL; - if (freevars == NULL || cellvars == NULL) { - PyObject *empty = PyTuple_New(0); - if (empty == NULL) - return NULL; - if (freevars == NULL) { - freevars = empty; - Py_INCREF(freevars); - } - if (cellvars == NULL) { - cellvars = empty; - Py_INCREF(cellvars); - } - Py_DECREF(empty); - } - if (!PyObject_CheckReadBuffer(code)) { PyErr_SetString(PyExc_TypeError, "bytecode object must be a single-segment read-only buffer"); return NULL; } - return (PyObject *)PyCode_New(argcount, nlocals, stacksize, flags, + 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); + firstlineno, lnotab); + Py_DECREF(empty); + return co; } static void |