Author: bugman Date: Mon Apr 29 11:37:47 2013 New Revision: 19607 URL: http://svn.gna.org/viewcvs/relax?rev=19607&view=rev Log: Big bug fix for a memory leak in the relaxation curve-fitting C module. Proper reference counting is used for the temporary 'element' Python objects used in the conversion between Python and C objects. The use of the Py_CLEAR() macro removes the memory leak. However the number of references as seen by sys.gettotalrefcount() in a debugging Python version keeps rising and might be a problem in the future. Modified: trunk/target_functions/relax_fit.c Modified: trunk/target_functions/relax_fit.c URL: http://svn.gna.org/viewcvs/relax/trunk/target_functions/relax_fit.c?rev=19607&r1=19606&r2=19607&view=diff ============================================================================== --- trunk/target_functions/relax_fit.c (original) +++ trunk/target_functions/relax_fit.c Mon Apr 29 11:37:47 2013 @@ -50,6 +50,7 @@ /* The diagonalised scaling matrix list argument element */ element = PySequence_GetItem(scaling_matrix_arg, i); scaling_matrix[i] = PyFloat_AsDouble(element); + Py_CLEAR(element); } /* Place the time related arguments into C arrays */ @@ -57,14 +58,17 @@ /* The value argument element */ element = PySequence_GetItem(values_arg, i); values[i] = PyFloat_AsDouble(element); + Py_CLEAR(element); /* The sd argument element */ element = PySequence_GetItem(sd_arg, i); sd[i] = PyFloat_AsDouble(element); + Py_CLEAR(element); /* The relax_times argument element */ element = PySequence_GetItem(relax_times_arg, i); relax_times[i] = PyFloat_AsDouble(element); + Py_CLEAR(element); } /* The macro for returning the Python None object */ @@ -94,8 +98,9 @@ /* Get the element */ element = PySequence_GetItem(params_arg, i); - /* Convert to a C double */ + /* Convert to a C double, then free the memory. */ params[i] = PyFloat_AsDouble(element); + Py_CLEAR(element); /* Scale the parameter */ params[i] = params[i] * scaling_matrix[i];