Skip to content

Commit

Permalink
Free resourceLocation in freeModelInstance() (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sommer authored Nov 1, 2023
1 parent c169b7a commit 0f285b6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
8 changes: 7 additions & 1 deletion src/cosimulation.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ ModelInstance *createModelInstance(
}

void freeModelInstance(ModelInstance *comp) {
free((void *)comp->instanceName);

if (!comp) return;

if (comp->instanceName) free((void*)comp->instanceName);

if (comp->resourceLocation) free((void*)comp->resourceLocation);

free(comp);
}

Expand Down
6 changes: 2 additions & 4 deletions src/fmi1Functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ fmiStatus fmiResetSlave(fmiComponent c) {
}

void fmiFreeSlaveInstance(fmiComponent c) {
ModelInstance *instance = (ModelInstance *)c;
freeModelInstance(instance);
freeModelInstance((ModelInstance*)c);
}

fmiStatus fmiSetRealInputDerivatives(fmiComponent c, const fmiValueReference vr[], size_t nvr,
Expand Down Expand Up @@ -588,8 +587,7 @@ fmiStatus fmiTerminate(fmiComponent c){
}

void fmiFreeModelInstance(fmiComponent c) {
ModelInstance *instance = (ModelInstance *)c;
freeModelInstance(instance);
freeModelInstance((ModelInstance*)c);
}

#endif // Model Exchange 1.0
5 changes: 1 addition & 4 deletions src/fmi2Functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,7 @@ fmi2Status fmi2Reset(fmi2Component c) {
}

void fmi2FreeInstance(fmi2Component c) {

if (S) {
freeModelInstance(S);
}
freeModelInstance((ModelInstance*)S);
}

// ---------------------------------------------------------------------------
Expand Down
4 changes: 0 additions & 4 deletions src/fmi3Functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,7 @@ fmi3Instance fmi3InstantiateScheduledExecution(
#endif
}


void fmi3FreeInstance(fmi3Instance instance) {

if (!instance) return;

freeModelInstance((ModelInstance*)instance);
}

Expand Down

0 comments on commit 0f285b6

Please sign in to comment.