Mercurial > cpython-lru_cache-weakref
diff Python/compile.c @ 30432:e8147f841a4a legacy-trunk
Improve the leak fix so that PyTuple_New is only called when needed.
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Tue, 16 Sep 2003 04:27:52 +0000 |
| parents | c2c10f1eb8e2 |
| children | b0c3d986f63f |
line wrap: on
line diff
--- a/Python/compile.c Tue Sep 16 03:41:45 2003 +0000 +++ b/Python/compile.c Tue Sep 16 04:27:52 2003 +0000 @@ -105,7 +105,7 @@ int stacksize; int flags; PyObject *co; - PyObject *empty; + PyObject *empty = NULL; PyObject *code; PyObject *consts; PyObject *names; @@ -135,19 +135,21 @@ 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; }
