mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Improve the leak fix so that PyTuple_New is only called when needed.
This commit is contained in:
parent
deb2dc6658
commit
cc1798e0c0
1 changed files with 11 additions and 9 deletions
|
@ -105,7 +105,7 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kw)
|
||||||
int stacksize;
|
int stacksize;
|
||||||
int flags;
|
int flags;
|
||||||
PyObject *co;
|
PyObject *co;
|
||||||
PyObject *empty;
|
PyObject *empty = NULL;
|
||||||
PyObject *code;
|
PyObject *code;
|
||||||
PyObject *consts;
|
PyObject *consts;
|
||||||
PyObject *names;
|
PyObject *names;
|
||||||
|
@ -135,19 +135,21 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kw)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
empty = PyTuple_New(0);
|
if (freevars == NULL || cellvars == NULL) {
|
||||||
if (empty == NULL)
|
empty = PyTuple_New(0);
|
||||||
return NULL;
|
if (empty == NULL)
|
||||||
if (freevars == NULL)
|
return NULL;
|
||||||
freevars = empty;
|
if (freevars == NULL)
|
||||||
if (cellvars == NULL)
|
freevars = empty;
|
||||||
cellvars = empty;
|
if (cellvars == NULL)
|
||||||
|
cellvars = empty;
|
||||||
|
}
|
||||||
|
|
||||||
co = (PyObject *) PyCode_New(argcount, nlocals, stacksize, flags,
|
co = (PyObject *) PyCode_New(argcount, nlocals, stacksize, flags,
|
||||||
code, consts, names, varnames,
|
code, consts, names, varnames,
|
||||||
freevars, cellvars, filename, name,
|
freevars, cellvars, filename, name,
|
||||||
firstlineno, lnotab);
|
firstlineno, lnotab);
|
||||||
Py_DECREF(empty);
|
Py_XDECREF(empty);
|
||||||
return co;
|
return co;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue