diff Python/compile.c @ 30433:c9f9eb13eac9 2.3

Backport leak fix for new code objects.
author Raymond Hettinger <python@rcn.com>
date Tue, 16 Sep 2003 04:36:33 +0000
parents 3442e7cdace8
children a7c4aa81eb85
line wrap: on
line diff
--- a/Python/compile.c	Mon Sep 15 18:20:13 2003 +0000
+++ b/Python/compile.c	Tue Sep 16 04:36:33 2003 +0000
@@ -104,6 +104,8 @@
 	int nlocals;
 	int stacksize;
 	int flags;
+	PyObject *co;
+	PyObject *empty = NULL;
 	PyObject *code;
 	PyObject *consts;
 	PyObject *names;
@@ -127,31 +129,28 @@
 			      &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