fsm: term: get parent pointer as late as possible

During FSM instance termination, fetch the parent pointer every time just
before using it, in case the child termination or cleanup callback wish to
change anything about the parent, e.g. to prevent event dispatch.

This patch was created to try and fix a problem that was in the end solved
differently. There is no actual need or use case for this at the moment, but it
generally makes sense to get the parent pointer as late as possible.

Change-Id: I999d7f29ba10281d4005c5163130bb2d80148362
This commit is contained in:
Neels Hofmeyr 2016-12-18 23:41:41 +01:00
parent 15492bcb26
commit 3faa014805
1 changed files with 4 additions and 1 deletions

View File

@ -421,7 +421,7 @@ void _osmo_fsm_inst_term(struct osmo_fsm_inst *fi,
enum osmo_fsm_term_cause cause, void *data,
const char *file, int line)
{
struct osmo_fsm_inst *parent = fi->proc.parent;
struct osmo_fsm_inst *parent;
uint32_t parent_term_event = fi->proc.parent_term_event;
LOGPFSMSRC(fi, file, line, "Terminating (cause = %s)\n",
@ -431,6 +431,7 @@ void _osmo_fsm_inst_term(struct osmo_fsm_inst *fi,
file, line);
/* delete ourselves from the parent */
parent = fi->proc.parent;
if (parent)
LOGPFSMSRC(fi, file, line, "Removing from parent %s\n",
osmo_fsm_inst_name(parent));
@ -441,6 +442,8 @@ void _osmo_fsm_inst_term(struct osmo_fsm_inst *fi,
fi->fsm->cleanup(fi, cause);
LOGPFSMSRC(fi, file, line, "Freeing instance\n");
/* Fetch parent again in case it has changed. */
parent = fi->proc.parent;
osmo_fsm_inst_free(fi);
/* indicate our termination to the parent */