parsers: fix memory leak in compute_phases_map_sets stable
authorLaurent Charignon <lcharignon@fb.com>
Thu, 06 Aug 2015 22:54:28 -0700
branchstable
changeset 25911 f4386cb3252e
parent 25900 d14590f90cb6
child 25925 23c4589fc678
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.
mercurial/parsers.c
--- 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));
 	}