Skip to content

Commit

Permalink
More memory leaks cleared (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
devyeshtandon committed Aug 8, 2016
1 parent a69dbc0 commit 0f2ee2a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
21 changes: 17 additions & 4 deletions mbdynFMI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,17 @@ void fmu2::GetDirectionalDerivatives(double** jacobian, int* inputStatesVRef, in
stateList[i] = inputStatesVRef[i-numOfContStates];
}

fmi2_real_t output[numOfContStates + inputLength];

jacobian = new double*[numOfContStates];
fmi2_real_t output[numOfContStates + inputLength];

for (int i=0; i<numOfContStates; i++){
fmistatus = fmi2_import_get_directional_derivative(fmu, stateList, numOfContStates + inputLength, &derList[i], 1, output , seedVector);
STATUSCHECK(fmistatus);
jacobian[i] = new double[numOfContStates + inputLength];

for (int j=0; j<numOfContStates + inputLength; j++)
jacobian[i][j] = output[j];
}
delete[] derList;
delete[] stateList;
}


Expand Down Expand Up @@ -349,6 +349,11 @@ void fmu2::Terminate(void){
fmi2_import_free_instance(fmu);
delete[] eventIndicators;
delete[] eventIndicatorsPrev;
delete[] currStates;
delete[] currStatesDer;

delete[] vrs;

}

void fmu2::InitializeAsSlave(const char* location, double tstart, double tend){
Expand Down Expand Up @@ -486,6 +491,8 @@ bool fmu1::CheckInput(const std::string s){
return ((fmi1_import_get_causality(v))==0);
}



void fmu1::SetValuesByVariable(const std::string s, double value){
fmi1_value_reference_t ref;
fmi1_variable_alias_kind_enu_t aliasKind;
Expand Down Expand Up @@ -592,6 +599,12 @@ void fmu1::Terminate(void){
fmi1_import_free_model_instance(fmu);
delete[] eventIndicators;
delete[] eventIndicatorsPrev;
delete[] currStates;
delete[] currStatesDer;
delete[] deriv;
delete[] vrs;



}

Expand Down
3 changes: 3 additions & 0 deletions mbdynFMI.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class fmu {
virtual void CSPropogate(double tcur, double dt) = 0;
virtual void TerminateSlave(void) = 0;


};

class fmu1 :public fmu{
Expand Down Expand Up @@ -117,6 +118,8 @@ class fmu1 :public fmu{
void InitializeAsSlave(const char* location, double tstart, double tend);
void CSPropogate(double tcur, double dt);
void TerminateSlave(void);


};

class fmu2 : public fmu{
Expand Down
Binary file modified mbdynFMI.o
Binary file not shown.
7 changes: 3 additions & 4 deletions module-FMU.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ ModuleFMU::~ModuleFMU(void)
delete[] seedVector;
}

delete[] currState;
delete[] jacobianInputVector;

delete[] jacobianInputVector;
delete model;
delete[] currState;
drivesContainer.clear();
}

Expand Down Expand Up @@ -252,8 +253,6 @@ ModuleFMU::AssJac(VariableSubMatrixHandler& WorkMat,
}
}

delete[] seedVector;

} else {
for(int i=1; i<=numOfContinousStates; i++)
WM.IncCoef(i , i, 1.);
Expand Down
Binary file modified module-FMU.o
Binary file not shown.

0 comments on commit 0f2ee2a

Please sign in to comment.