# HG changeset patch # User Laurent Charignon # Date 2015-08-07 05:54:28 # Node ID f4386cb3252ef6eb1b2911178d9207bf465effec # Parent d14590f90cb6e6780bbe7046e0c8fd603fd118e8 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. diff --git a/mercurial/parsers.c b/mercurial/parsers.c --- a/mercurial/parsers.c +++ b/mercurial/parsers.c @@ -1113,6 +1113,7 @@ static PyObject *compute_phases_map_sets 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 @@ static PyObject *compute_phases_map_sets * 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)); }