changeset 25911:f4386cb3252e stable

parsers: fix memory leak in compute_phases_map_sets PySet_Add increments the reference of the added object to the set, see: https://hg.python.org/cpython/file/2.6/Objects/setobject.c#l379 Before this patch we were forgetting to decrement the reference count after adding objects to the phaseset. This patch fixes the issue and makes the reference count right so that these objects can be properly garbage collected.
author Laurent Charignon <lcharignon@fb.com>
date Thu, 06 Aug 2015 22:54:28 -0700
parents d14590f90cb6
children 23c4589fc678
files mercurial/parsers.c
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/parsers.c	Mon Aug 03 20:34:36 2015 +0100
+++ b/mercurial/parsers.c	Thu Aug 06 22:54:28 2015 -0700
@@ -1113,6 +1113,7 @@
 	PyObject *phaseroots = NULL;
 	PyObject *phaseset = NULL;
 	PyObject *phasessetlist = NULL;
+	PyObject *rev = NULL;
 	Py_ssize_t len = index_length(self) - 1;
 	Py_ssize_t numphase = 0;
 	Py_ssize_t minrevallphases = 0;
@@ -1172,7 +1173,9 @@
 		 * is computed as a difference */
 		if (phase != 0) {
 			phaseset = PyList_GET_ITEM(phasessetlist, phase);
-			PySet_Add(phaseset, PyInt_FromLong(i));
+			rev = PyInt_FromLong(i);
+			PySet_Add(phaseset, rev);
+			Py_XDECREF(rev);
 		}
 		PyList_SET_ITEM(phaseslist, i, PyInt_FromLong(phase));
 	}