diff Python/modsupport.c @ 6613:2e874a5a912f legacy-trunk

Plug memory leak in Py_BuildValue when using {...} to construct dictionaries.
author Guido van Rossum <guido@python.org>
date Thu, 20 Nov 1997 20:35:45 +0000
parents 4514a5ea3ec4
children 8e86a797e596
line wrap: on
line diff
--- a/Python/modsupport.c	Thu Nov 20 19:56:38 1997 +0000
+++ b/Python/modsupport.c	Thu Nov 20 20:35:45 1997 +0000
@@ -169,6 +169,7 @@
 		return NULL;
 	for (i = 0; i < n; i+= 2) {
 		PyObject *k, *v;
+		int err;
 		k = do_mkvalue(p_format, p_va);
 		if (k == NULL) {
 			Py_DECREF(d);
@@ -180,9 +181,10 @@
 			Py_DECREF(d);
 			return NULL;
 		}
-		if (PyDict_SetItem(d, k, v) < 0) {
-			Py_DECREF(k);
-			Py_DECREF(v);
+		err = PyDict_SetItem(d, k, v);
+		Py_DECREF(k);
+		Py_DECREF(v);
+		if (err < 0) {
 			Py_DECREF(d);
 			return NULL;
 		}