]> granicus.if.org Git - python/commitdiff
Fix leak discovered in test_new by Michael Hudson.
authorRaymond Hettinger <python@rcn.com>
Mon, 15 Sep 2003 21:43:16 +0000 (21:43 +0000)
committerRaymond Hettinger <python@rcn.com>
Mon, 15 Sep 2003 21:43:16 +0000 (21:43 +0000)
Will backport to 2.3.1

Python/compile.c

index 69a07af31d77f47925694a5544747dedb9f039dd..f94a3ac6f438889638027e3f25560b65b59e6ded 100644 (file)
@@ -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