]> granicus.if.org Git - python/commitdiff
Plug a memory leak in Py_InitModule4(): when PyDict_SetItemString() failed,
authorFred Drake <fdrake@acm.org>
Sat, 4 Aug 2001 03:11:25 +0000 (03:11 +0000)
committerFred Drake <fdrake@acm.org>
Sat, 4 Aug 2001 03:11:25 +0000 (03:11 +0000)
the object being inserted was not being DECREFed.

This closes SF bug #444486.

Python/modsupport.c

index eb0818cc95cae3b7bbe68c4d0c6aa8493b2fce74..8fad54a3233500b3f88cd5158ff3cf5ed68bc066 100644 (file)
@@ -60,14 +60,18 @@ Py_InitModule4(char *name, PyMethodDef *methods, char *doc,
                v = PyCFunction_New(ml, passthrough);
                if (v == NULL)
                        return NULL;
-               if (PyDict_SetItemString(d, ml->ml_name, v) != 0)
+               if (PyDict_SetItemString(d, ml->ml_name, v) != 0) {
+                       Py_DECREF(v);
                        return NULL;
+               }
                Py_DECREF(v);
        }
        if (doc != NULL) {
                v = PyString_FromString(doc);
-               if (v == NULL || PyDict_SetItemString(d, "__doc__", v) != 0)
+               if (v == NULL || PyDict_SetItemString(d, "__doc__", v) != 0) {
+                       Py_DECREF(v);
                        return NULL;
+               }
                Py_DECREF(v);
        }
        return m;