#3095: don't leak values from Py_BuildValue.
authorGeorg Brandl <georg@python.org>
Fri, 13 Jun 2008 06:56:50 +0000 (06:56 +0000)
committerGeorg Brandl <georg@python.org>
Fri, 13 Jun 2008 06:56:50 +0000 (06:56 +0000)
Modules/_multiprocessing/multiprocessing.c

index 1050e1f832fb576cb7d5bcb05d3c04c9fee1d709..a38cd89c71cb20b5aec0ba4a3c370104f01ef8c3 100644 (file)
@@ -215,7 +215,7 @@ static PyMethodDef module_methods[] = {
 PyMODINIT_FUNC\r
 init_multiprocessing(void)\r
 {\r
-       PyObject *module, *temp;\r
+       PyObject *module, *temp, *value;\r
 \r
        /* Initialize module */\r
        module = Py_InitModule("_multiprocessing", module_methods);\r
@@ -284,11 +284,12 @@ init_multiprocessing(void)
        temp = PyDict_New();\r
        if (!temp)\r
                return;\r
-       if (PyModule_AddObject(module, "flags", temp) < 0)\r
-               return;\r
-\r
-#define ADD_FLAG(name) \\r
-    if (PyDict_SetItemString(temp, #name, Py_BuildValue("i", name)) < 0) return\r
+#define ADD_FLAG(name)                                           \\r
+       value = Py_BuildValue("i", name);                         \\r
+       if (value == NULL) { Py_DECREF(temp); return; }           \\r
+       if (PyDict_SetItemString(temp, #name, value) < 0) {       \\r
+               Py_DECREF(temp); Py_DECREF(value); return; }      \\r
+       Py_DECREF(value)\r
        \r
 #ifdef HAVE_SEM_OPEN\r
        ADD_FLAG(HAVE_SEM_OPEN);\r
@@ -305,4 +306,6 @@ init_multiprocessing(void)
 #ifdef HAVE_BROKEN_SEM_UNLINK\r
        ADD_FLAG(HAVE_BROKEN_SEM_UNLINK);\r
 #endif\r
+       if (PyModule_AddObject(module, "flags", temp) < 0)\r
+               return;\r
 }\r