comparison mercurial/parsers.c @ 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 895f04955a49
children ff89383a97db
comparison
equal deleted inserted replaced
25900:d14590f90cb6 25911:f4386cb3252e
1111 PyObject *ret = NULL; 1111 PyObject *ret = NULL;
1112 PyObject *phaseslist = NULL; 1112 PyObject *phaseslist = NULL;
1113 PyObject *phaseroots = NULL; 1113 PyObject *phaseroots = NULL;
1114 PyObject *phaseset = NULL; 1114 PyObject *phaseset = NULL;
1115 PyObject *phasessetlist = NULL; 1115 PyObject *phasessetlist = NULL;
1116 PyObject *rev = NULL;
1116 Py_ssize_t len = index_length(self) - 1; 1117 Py_ssize_t len = index_length(self) - 1;
1117 Py_ssize_t numphase = 0; 1118 Py_ssize_t numphase = 0;
1118 Py_ssize_t minrevallphases = 0; 1119 Py_ssize_t minrevallphases = 0;
1119 Py_ssize_t minrevphase = 0; 1120 Py_ssize_t minrevphase = 0;
1120 Py_ssize_t i = 0; 1121 Py_ssize_t i = 0;
1170 phase = phases[i]; 1171 phase = phases[i];
1171 /* We only store the sets of phase for non public phase, the public phase 1172 /* We only store the sets of phase for non public phase, the public phase
1172 * is computed as a difference */ 1173 * is computed as a difference */
1173 if (phase != 0) { 1174 if (phase != 0) {
1174 phaseset = PyList_GET_ITEM(phasessetlist, phase); 1175 phaseset = PyList_GET_ITEM(phasessetlist, phase);
1175 PySet_Add(phaseset, PyInt_FromLong(i)); 1176 rev = PyInt_FromLong(i);
1177 PySet_Add(phaseset, rev);
1178 Py_XDECREF(rev);
1176 } 1179 }
1177 PyList_SET_ITEM(phaseslist, i, PyInt_FromLong(phase)); 1180 PyList_SET_ITEM(phaseslist, i, PyInt_FromLong(phase));
1178 } 1181 }
1179 ret = PyList_New(2); 1182 ret = PyList_New(2);
1180 if (ret == NULL) 1183 if (ret == NULL)