Patchwork [7,of,7] parsers: avoid leaking several PyObjects in index_stats

login
register
mail settings
Submitter Augie Fackler
Date Jan. 23, 2015, 9:06 p.m.
Message ID <9265ecdf6ce8efc38c1d.1422047204@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/7544/
State Accepted
Commit bd307b462ce2a7d07b2960c6763cb0f3669115f1
Headers show

Comments

Augie Fackler - Jan. 23, 2015, 9:06 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1422046536 18000
#      Fri Jan 23 15:55:36 2015 -0500
# Branch stable
# Node ID 9265ecdf6ce8efc38c1dea34ca037fcb320c7d9f
# Parent  8dddf2c91b60c98f9f374c46d11e6a1fe28e2ab2
parsers: avoid leaking several PyObjects in index_stats

Found with cpychecker.
Matt Mackall - Jan. 23, 2015, 10:19 p.m.
On Fri, 2015-01-23 at 16:06 -0500, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1422046536 18000
> #      Fri Jan 23 15:55:36 2015 -0500
> # Branch stable
> # Node ID 9265ecdf6ce8efc38c1dea34ca037fcb320c7d9f
> # Parent  8dddf2c91b60c98f9f374c46d11e6a1fe28e2ab2
> parsers: avoid leaking several PyObjects in index_stats

These are queued for stable, thanks.

Patch

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -818,19 +818,27 @@  static PyObject *index_clearcaches(index
 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 @@  static PyObject *index_stats(indexObject
 
 bail:
 	Py_XDECREF(obj);
+	Py_XDECREF(t);
 	return NULL;
 }