LennartHennigs / SimpleFSM

Arduino/ESP library to simplify setting up and running a state machine.
MIT License
66 stars 15 forks source link

Destructor of SimpleFSM uses free() for Transitions #8

Closed bloodhoundmichael closed 11 months ago

bloodhoundmichael commented 1 year ago

The destructor of SimpleFSM:

SimpleFSM::~SimpleFSM() {
  free(transitions);
  free(timed);
  transitions = NULL;
  timed = NULL;
}

In many examples the stack is being used to store the transitions. For example SimpleTransitions.ino:

Transition transitions[] = {
  Transition(&s[0], &s[1], light_switch_flipped, on_to_off),
  Transition(&s[1], &s[0], light_switch_flipped, off_to_on)
};

There should be a well defined and documented way how to handle memory management with SimpleFSM.

LennartHennigs commented 11 months ago

Hey, thanks for pointing this out. You are right, of course. Will merge it.

(And thanks for all the other reviews and pull requests. Will now work through them one by one 😄 )