Skip to content

Commit

Permalink
Fix for memory leak in fmi2GetFMUstate (#11233)
Browse files Browse the repository at this point in the history
  - De-allocate old FMUstate object before updating reference with newly allocated object.
  • Loading branch information
sturmk committed Sep 27, 2023
1 parent 865f737 commit 6e4fded
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,10 @@ fmi2Status fmi2GetFMUstate(fmi2Component c, fmi2FMUstate* FMUstate)
//printRingBufferSimulationData(fmudata->simulationData, fmudata); // original ringBuffer data
//printRingBufferSimulationData(internal_state->simulationData, fmudata); // copied ringBuffer data

/* release previous fmu state if existent */
/* TODO: ideally, previous state's memory should be re-used instead of re-allocation */
if (*FMUstate != NULL) fmi2FreeFMUstate(c, FMUstate);

// return the fmu state
*FMUstate = (fmi2FMUstate) internal_state;
return fmi2OK;
Expand Down

0 comments on commit 6e4fded

Please sign in to comment.