diff Python/modsupport.c @ 18991:360cece76123 legacy-trunk

Plug a memory leak in Py_InitModule4(): when PyDict_SetItemString() failed, the object being inserted was not being DECREFed. This closes SF bug #444486.
author Fred Drake <fdrake@acm.org>
date Sat, 04 Aug 2001 03:11:25 +0000
parents 79c676f9b34a
children 7257e87e0720
line wrap: on
line diff
--- a/Python/modsupport.c	Sat Aug 04 01:58:36 2001 +0000
+++ b/Python/modsupport.c	Sat Aug 04 03:11:25 2001 +0000
@@ -60,14 +60,18 @@
 		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;