changeset 23948:bd307b462ce2 stable

parsers: avoid leaking several PyObjects in index_stats Found with cpychecker.
author Augie Fackler <augie@google.com>
date Fri, 23 Jan 2015 15:55:36 -0500
parents 2cb49fba9736
children 8efb7130a519
files mercurial/parsers.c
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/parsers.c	Fri Jan 23 15:50:40 2015 -0500
+++ b/mercurial/parsers.c	Fri Jan 23 15:55:36 2015 -0500
@@ -818,19 +818,27 @@
 static PyObject *index_stats(indexObject *self)
 {
 	PyObject *obj = PyDict_New();
+	PyObject *t = NULL;
 
 	if (obj == NULL)
 		return NULL;
 
 #define istat(__n, __d) \
-	if (PyDict_SetItemString(obj, __d, PyInt_FromSsize_t(self->__n)) == -1) \
-		goto bail;
+	t = PyInt_FromSsize_t(self->__n); \
+	if (!t) \
+		goto bail; \
+	if (PyDict_SetItemString(obj, __d, t) == -1) \
+		goto bail; \
+	Py_DECREF(t);
 
 	if (self->added) {
 		Py_ssize_t len = PyList_GET_SIZE(self->added);
-		if (PyDict_SetItemString(obj, "index entries added",
-					 PyInt_FromSsize_t(len)) == -1)
+		t = PyInt_FromSsize_t(len);
+		if (!t)
 			goto bail;
+		if (PyDict_SetItemString(obj, "index entries added", t) == -1)
+			goto bail;
+		Py_DECREF(t);
 	}
 
 	if (self->raw_length != self->length - 1)
@@ -850,6 +858,7 @@
 
 bail:
 	Py_XDECREF(obj);
+	Py_XDECREF(t);
 	return NULL;
 }