[Python-checkins] r64223 - python/trunk/Modules/_multiprocessing/multiprocessing.c

georg.brandl python-checkins at python.org
Fri Jun 13 08:56:50 CEST 2008


Author: georg.brandl
Date: Fri Jun 13 08:56:50 2008
New Revision: 64223

Log:
#3095: don't leak values from Py_BuildValue.


Modified:
   python/trunk/Modules/_multiprocessing/multiprocessing.c

Modified: python/trunk/Modules/_multiprocessing/multiprocessing.c
==============================================================================
--- python/trunk/Modules/_multiprocessing/multiprocessing.c	(original)
+++ python/trunk/Modules/_multiprocessing/multiprocessing.c	Fri Jun 13 08:56:50 2008
@@ -215,7 +215,7 @@
 PyMODINIT_FUNC
 init_multiprocessing(void)
 {
-	PyObject *module, *temp;
+	PyObject *module, *temp, *value;
 
 	/* Initialize module */
 	module = Py_InitModule("_multiprocessing", module_methods);
@@ -284,11 +284,12 @@
 	temp = PyDict_New();
 	if (!temp)
 		return;
-	if (PyModule_AddObject(module, "flags", temp) < 0)
-		return;
-
-#define ADD_FLAG(name) \
-    if (PyDict_SetItemString(temp, #name, Py_BuildValue("i", name)) < 0) return
+#define ADD_FLAG(name)						  \
+	value = Py_BuildValue("i", name);			  \
+	if (value == NULL) { Py_DECREF(temp); return; }		  \
+	if (PyDict_SetItemString(temp, #name, value) < 0) {	  \
+		Py_DECREF(temp); Py_DECREF(value); return; }	  \
+	Py_DECREF(value)
 	
 #ifdef HAVE_SEM_OPEN
 	ADD_FLAG(HAVE_SEM_OPEN);
@@ -305,4 +306,6 @@
 #ifdef HAVE_BROKEN_SEM_UNLINK
 	ADD_FLAG(HAVE_BROKEN_SEM_UNLINK);
 #endif
+	if (PyModule_AddObject(module, "flags", temp) < 0)
+		return;
 }


More information about the Python-checkins mailing list