[Python-checkins] commit of r41553 - python/trunk/Python

neal.norwitz@python.org neal.norwitz at python.org
Sun Nov 27 21:38:36 CET 2005


Author: neal.norwitz
Date: Sun Nov 27 21:38:31 2005
New Revision: 41553

Modified:
   python/trunk/Python/bltinmodule.c
Log:
Fix memory leaks

Modified: python/trunk/Python/bltinmodule.c
==============================================================================
--- python/trunk/Python/bltinmodule.c	(original)
+++ python/trunk/Python/bltinmodule.c	Sun Nov 27 21:38:31 2005
@@ -404,7 +404,7 @@
 	int dont_inherit = 0;
 	int supplied_flags = 0;
 	PyCompilerFlags cf;
-	PyObject *result, *cmd, *tmp = NULL;
+	PyObject *result = NULL, *cmd, *tmp = NULL;
 	int length;
 
 	if (!PyArg_ParseTuple(args, "Oss|ii:compile", &cmd, &filename,
@@ -427,7 +427,7 @@
 	if ((size_t)length != strlen(str)) {
 		PyErr_SetString(PyExc_TypeError,
 				"compile() expected string without null bytes");
-		return NULL;
+		goto cleanup;
 	}
 
 	if (strcmp(startstr, "exec") == 0)
@@ -439,7 +439,7 @@
 	else {
 		PyErr_SetString(PyExc_ValueError,
 		   "compile() arg 3 must be 'exec' or 'eval' or 'single'");
-		return NULL;
+		goto cleanup;
 	}
 
 	if (supplied_flags &
@@ -447,7 +447,7 @@
 	{
 		PyErr_SetString(PyExc_ValueError,
 				"compile(): unrecognised flags");
-		return NULL;
+		goto cleanup;
 	}
 	/* XXX Warn if (supplied_flags & PyCF_MASK_OBSOLETE) != 0? */
 
@@ -455,6 +455,7 @@
 		PyEval_MergeCompilerFlags(&cf);
 	}
 	result = Py_CompileStringFlags(str, filename, start, &cf);
+cleanup:
 	Py_XDECREF(tmp);
 	return result;
 }
@@ -580,8 +581,10 @@
 		cf.cf_flags |= PyCF_SOURCE_IS_UTF8;
 	}
 #endif
-	if (PyString_AsStringAndSize(cmd, &str, NULL))
+	if (PyString_AsStringAndSize(cmd, &str, NULL)) {
+		Py_XDECREF(tmp);
 		return NULL;
+	}
 	while (*str == ' ' || *str == '\t')
 		str++;
 


More information about the Python-checkins mailing list