Revert "fsm: do not terminate child FSMs early"

This reverts commit 5ec91980ac2224aa1e9bf070a0e382d0d8c2b729.

More or less like I expected, it creates fall-out.  osmo-msc master builds are failing, as are the open build service builds.  The patch has therefor *not* been sufficiently tested.

Change-Id: I8d961d7bbd91b6a8d7691f24cb67720c3d001c7e
diff --git a/src/fsm.c b/src/fsm.c
index dd3538f..d8751c9 100644
--- a/src/fsm.c
+++ b/src/fsm.c
@@ -509,6 +509,9 @@
 	LOGPFSMSRC(fi, file, line, "Terminating (cause = %s)\n",
 		   osmo_fsm_term_cause_name(cause));
 
+	_osmo_fsm_inst_term_children(fi, OSMO_FSM_TERM_PARENT, NULL,
+				     file, line);
+
 	/* delete ourselves from the parent */
 	parent = fi->proc.parent;
 	if (parent) {
@@ -521,10 +524,6 @@
 	if (fi->fsm->cleanup)
 		fi->fsm->cleanup(fi, cause);
 
-	/* terminate all children */
-	_osmo_fsm_inst_term_children(fi, OSMO_FSM_TERM_PARENT, NULL,
-				     file, line);
-	
 	LOGPFSMSRC(fi, file, line, "Freeing instance\n");
 	/* Fetch parent again in case it has changed. */
 	parent = fi->proc.parent;