summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-09-16 04:36:33 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-09-16 04:36:33 (GMT)
commitc866ac776c65799fc55da397c582ea583330ea9c (patch)
tree802560b6f5cee9a0d1b518400cad8dc81c2c27e1 /Python
parent194e909154aaccaa3261c543b43fea8598689c8a (diff)
downloadcpython-c866ac776c65799fc55da397c582ea583330ea9c.zip
cpython-c866ac776c65799fc55da397c582ea583330ea9c.tar.gz
cpython-c866ac776c65799fc55da397c582ea583330ea9c.tar.bz2
Backport leak fix for new code objects.
Diffstat (limited to 'Python')
-rw-r--r--Python/compile.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 38624d4..9ac0032 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 = NULL;
PyObject *code;
PyObject *consts;
PyObject *names;
@@ -127,31 +129,28 @@ 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,
+ 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);
+ firstlineno, lnotab);
+ Py_XDECREF(empty);
+ return co;
}
static void