Author: bugman Date: Mon Apr 29 10:04:56 2013 New Revision: 19599 URL: http://svn.gna.org/viewcvs/relax?rev=19599&view=rev Log: Shifted the C array creation to the relax_fit C module header. The params, values, sd, relax_times, and scaling_matrix C arrays are now declared and allocated in the header file rather than using malloc() calls in the setup() function. This is to attempt to remove a memory leak. The arrays are now of fixed length and reused for each setup() call. These, as well as the other variables declared in the header are no longer declared in the functions. Modified: trunk/target_functions/relax_fit.c trunk/target_functions/relax_fit.h Modified: trunk/target_functions/relax_fit.c URL: http://svn.gna.org/viewcvs/relax/trunk/target_functions/relax_fit.c?rev=19599&r1=19598&r2=19599&view=diff ============================================================================== --- trunk/target_functions/relax_fit.c (original) +++ trunk/target_functions/relax_fit.c Mon Apr 29 10:04:56 2013 @@ -34,8 +34,6 @@ PyObject *element; /* Normal declarations */ - extern double *params, *values, *sd, *relax_times, *scaling_matrix; - extern int num_params, num_times; int i; /* The keyword list */ @@ -44,13 +42,6 @@ /* Parse the function arguments */ if (!PyArg_ParseTupleAndKeywords(args, keywords, "iiOOOO", keyword_list, &num_params, &num_times, &values_arg, &sd_arg, &relax_times_arg, &scaling_matrix_arg)) return NULL; - - /* Dynamic C arrays */ - params = (double *) malloc(sizeof(double)*num_params); - values = (double *) malloc(sizeof(double)*num_times); - sd = (double *) malloc(sizeof(double)*num_times); - relax_times = (double *) malloc(sizeof(double)*num_times); - scaling_matrix = (double *) malloc(sizeof(double)*num_params); /* Place the parameter related arguments into C arrays */ for (i = 0; i < num_params; i++) { @@ -90,7 +81,6 @@ /* Declarations */ PyObject *params_arg; PyObject *element; - extern double *params; int i; /* Parse the function arguments, the only argument should be the parameter array */ @@ -152,8 +142,6 @@ /* Declarations */ PyObject *back_calc_py = PyList_New(num_times); - extern double back_calc[]; - extern int num_times; int i; /* Copy the values out of the C array into the Python array */ Modified: trunk/target_functions/relax_fit.h URL: http://svn.gna.org/viewcvs/relax/trunk/target_functions/relax_fit.h?rev=19599&r1=19598&r2=19599&view=diff ============================================================================== --- trunk/target_functions/relax_fit.h (original) +++ trunk/target_functions/relax_fit.h Mon Apr 29 10:04:56 2013 @@ -37,8 +37,10 @@ /* Variables sent to the setup function to be stored for later use */ int num_params, num_times; -/* Pointers to PyObjects */ -double *params, *values, *sd, *relax_times, *scaling_matrix; - /* Variables used for storage during the function calls of optimisation */ double back_calc[MAXTIMES]; +double params[MAXPARAMS]; +double values[MAXTIMES]; +double sd[MAXTIMES]; +double relax_times[MAXTIMES]; +double scaling_matrix[MAXPARAMS];