Changeset 22410


Ignore:
Timestamp:
02/08/18 10:05:08 (7 years ago)
Author:
erobo
Message:

CHG: fixed memory leaks among other small things

Location:
issm/trunk-jpl/src/c
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/classes/Numberedcostfunction.h

    r22407 r22410  
    3838                /*}}}*/
    3939                Numberedcostfunction(char* in_name, int in_definitionenum,int number_cost_functions_in,int* cost_functions_list_in){/*{{{*/
    40 
    4140                        _assert_(number_cost_functions_in>0);
    4241                        _assert_(cost_functions_list_in);
     
    108107                 IssmDouble Response(FemModel* femmodel){/*{{{*/
    109108                       
     109                         _assert_(number_cost_functions>0 && number_cost_functions<1e3);
    110110                         /*output:*/
    111111                         IssmDouble value;
    112112
    113113                         /*Intermediary*/
    114                          int      num_responses;
    115                          int     *responses      = NULL;
    116114                         Results *cost_functions = NULL;
    117115
    118 
    119                          /*Recover parameters*/
    120                          femmodel->parameters->FindParam(&num_responses,InversionNumCostFunctionsEnum);
    121                          femmodel->parameters->FindParam(&responses,NULL,InversionCostFunctionsEnum);
    122 
    123116                         /*Get the value of all cost functions*/
    124                          femmodel->RequestedOutputsx(&cost_functions,responses,num_responses);
     117                         femmodel->RequestedOutputsx(&cost_functions,cost_functions_list,number_cost_functions);
    125118
    126119                         /*Get and add all contributions one by one*/
    127                          IssmDouble  J=0;
    128                          IssmDouble* Jlist = xNew<IssmDouble>(num_responses);
    129                          for(int i=0;i<num_responses;i++){
     120                         IssmDouble  J=0.;
     121                         IssmDouble* Jlist = xNew<IssmDouble>(number_cost_functions);
     122                         for(int i=0;i<number_cost_functions;i++){
    130123                                 ExternalResult* result=(ExternalResult*)cost_functions->GetObjectByOffset(i);
    131124                                 Jlist[i] = reCast<IssmDouble>(result->GetValue());
    132125                                 J       += Jlist[i];
    133126                         }
    134                          _assert_(cost_functions->Size()==num_responses);
     127                         _assert_(cost_functions->Size()==number_cost_functions);
    135128                         
    136129                         
    137130                        value = J;             
    138131                        _printf_("J: "<<J<<"\n");
    139                          
    140                         // _error_("STOP!");
    141132
    142133                         /*done:*/
    143                          return value;
     134                        delete  cost_functions;
     135                        xDelete<IssmDouble>(Jlist);
     136                        return value;
    144137                 }
    145138                 /*}}}*/
  • issm/trunk-jpl/src/c/modules/ModelProcessorx/CreateOutputDefinitions.cpp

    r22409 r22410  
    182182                                for(j=0;j<numnodalvalues;j++){
    183183                                        char* string=NULL;
    184                                         IssmDouble* matrix = NULL;
    185184                                        string = nodalvalue_name_s[j];    xDelete<char>(string);
    186185                                }
     
    322321                                char **ncf_name_s             = NULL;
    323322                                char **ncf_definitionstring_s = NULL;
     323                                char **cost_functions         = NULL;
    324324                                int    cost_function ,domaintype;
    325325                                int    num_cost_functions;
    326                                 char **cost_functions         = NULL;
    327                                 int    num_costfunc;
    328                                 char **cm_responses           = NULL;
    329326
    330327                                /*Process cost functions and convert from string to enums*/
     
    337334                                }
    338335
    339                                 iomodel->FetchData(1,"md.numberedcostfunction.cost_functions_coefficients");
     336                                //iomodel->FetchData(1,"md.numberedcostfunction.cost_functions_coefficients");
    340337
    341338                                iomodel->FetchMultipleData(&ncf_name_s,&numout,"md.numberedcostfunction.name");
     
    362359                                for(j=0;j<numout;j++){
    363360
    364                                         output_definitions->AddObject(new Numberedcostfunction(ncf_name_s[j],StringToEnumx(ncf_definitionstring_s[j]),num_costfunc,cost_function_enums));
    365 
    366                                 }
    367 
    368                                 parameters->AddObject(iomodel->CopyConstantObject("md.inversion.num_cost_functions",InversionNumCostFunctionsEnum));
     361                                        output_definitions->AddObject(new Numberedcostfunction(ncf_name_s[j],StringToEnumx(ncf_definitionstring_s[j]),num_cost_functions,cost_function_enums));
     362
     363                                }
     364
    369365                               
    370                                 iomodel->FindConstant(&cm_responses,&num_costfunc,"md.inversion.cost_functions");
    371                                 //if(num_costfunc<1) error ("no cost functions found");
    372                                 int* costfunc_enums=xNew<int>(num_costfunc);
    373                                 for(int i=0;i<num_costfunc;i++){
    374                                                 costfunc_enums[i]=StringToEnumx(cm_responses[i]);
    375                                                 xDelete<char>(cm_responses[i]);
    376                                         }
    377                                 xDelete<char*>(cm_responses);
    378                                
    379                                 parameters->AddObject(new IntVecParam(InversionCostFunctionsEnum,costfunc_enums,num_costfunc));
    380                                 xDelete<int>(costfunc_enums);
    381 
    382366                                /*Free data: */
    383                                 iomodel->DeleteData(1,"md.inversion.cost_functions_coefficients");
     367                                //iomodel->DeleteData(1,"md.inversion.cost_functions_coefficients");
     368                                iomodel->DeleteData(2,"md.numberedcostfunction.name","md.numberedcostfunction.definitionstring");
    384369                                xDelete<int>(cost_function_enums);
    385370                                for(int i=0;i<num_cost_functions;i++) xDelete<char>(cost_functions[i]);
    386371                                xDelete<char*>(cost_functions);
     372
     373                                /*Free ressources:*/
     374                                for(j=0;j<numout;j++){
     375                                        xDelete<char>(ncf_name_s[j]);
     376                                        xDelete<char>(ncf_definitionstring_s[j]);
     377                                }
     378                                xDelete<char*>(ncf_name_s);
     379                                xDelete<char*>(ncf_definitionstring_s);
    387380                        }
    388381                        /*}}}*/
Note: See TracChangeset for help on using the changeset viewer.