]> granicus.if.org Git - python/commitdiff
Improve the leak fix so that PyTuple_New is only called when needed.
authorRaymond Hettinger <python@rcn.com>
Tue, 16 Sep 2003 04:27:52 +0000 (04:27 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 16 Sep 2003 04:27:52 +0000 (04:27 +0000)
Python/compile.c

index f94a3ac6f438889638027e3f25560b65b59e6ded..b95732b046e75d17ef6cfba2e1cf8cad73a897a3 100644 (file)
@@ -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;
 }