Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Fix stateselection destructor
Browse files Browse the repository at this point in the history
- Fixed a double free for FMUs with state selection
- Fixed a use of a pointer after it was free'd

Belonging to [master]:
  - #2391
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Apr 24, 2018
1 parent 0b569cc commit c51b823
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
9 changes: 4 additions & 5 deletions SimulationRuntime/c/simulation/solver/model_help.c
Expand Up @@ -1189,11 +1189,6 @@ void deInitializeDataStruc(DATA *data)
free(data->simulationInfo->booleanParameter);
omc_alloc_interface.free_uncollectable(data->simulationInfo->stringParameter);

if (data->modelData->nStateSets) {
/* free buffer for state sets */
omc_alloc_interface.free_uncollectable(data->simulationInfo->stateSetData);
}

if (data->modelData->nMixedSystems) {
/* free buffer of mixed systems */
omc_alloc_interface.free_uncollectable(data->simulationInfo->mixedSystemData);
Expand Down Expand Up @@ -1237,6 +1232,10 @@ void deInitializeDataStruc(DATA *data)
/* free stateset data */
freeStateSetData(data);
#endif
if (data->modelData->nStateSets) {
/* free buffer for state sets */
omc_alloc_interface.free_uncollectable(data->simulationInfo->stateSetData);
}

/* free parameter sensitivities */
if (omc_flag[FLAG_IDAS])
Expand Down
4 changes: 0 additions & 4 deletions SimulationRuntime/fmi/export/fmi1/fmu1_model_interface.c
Expand Up @@ -858,10 +858,6 @@ fmiStatus fmiTerminate(fmiComponent c)
/* free linear system data */
freeLinearSystems(comp->fmuData, comp->threadData);
#endif
#if !defined(OMC_NO_STATESELECTION)
/* free stateset data */
freeStateSetData(comp->fmuData);
#endif

/* free stateset data */
deInitializeDataStruc(comp->fmuData);
Expand Down
4 changes: 0 additions & 4 deletions SimulationRuntime/fmi/export/fmi2/fmu2_model_interface.c
Expand Up @@ -643,10 +643,6 @@ fmi2Status fmi2Terminate(fmi2Component c)
#if !defined(OMC_NUM_LINEAR_SYSTEMS) || OMC_NUM_LINEAR_SYSTEMS>0
/* free linear system data */
freeLinearSystems(comp->fmuData, comp->threadData);
#endif
#if !defined(OMC_NO_STATESELECTION)
/* free stateset data */
freeStateSetData(comp->fmuData);
#endif
/* free data struct */
deInitializeDataStruc(comp->fmuData);
Expand Down

0 comments on commit c51b823

Please sign in to comment.