invalidate vsub->msc_conn_ref when msc_a is discarded

We have an msc_conn_ref pointer from vlr_subscr to an active msc_a
instance. So far, we just keep it pointing at discarded memory. Instead,
make sure it goes back to NULL when the msc_a instance deallocates.

This way the VLR can reliably tell whether a given VLR entry still has
an active connection or is just inactively caching the subscriber.

Related: SYS#6860 OS#4721
Change-Id: Ic63d01d220b63453976fe06a7c6b606f97172c99
diff --git a/src/libmsc/msc_a.c b/src/libmsc/msc_a.c
index 4fb30c4..70d9bf7 100644
--- a/src/libmsc/msc_a.c
+++ b/src/libmsc/msc_a.c
@@ -999,6 +999,7 @@
 void msc_a_fsm_cleanup(struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause cause)
 {
 	struct msc_a *msc_a = msc_a_fi_priv(fi);
+	struct vlr_subscr *vsub = msc_a_vsub(msc_a);
 
 	trans_conn_closed(msc_a);
 
@@ -1006,6 +1007,10 @@
 		LOG_MSC_A(msc_a, LOGL_ERROR, "Deallocating active transactions failed\n");
 
 	LOG_MSC_A_CAT(msc_a, DREF, LOGL_DEBUG, "max total use count was %d\n", msc_a->max_total_use_count);
+
+	/* Invalidate the active conn in VLR subscriber state, if any. */
+	if (vsub && vsub->msc_conn_ref == msc_a)
+		vsub->msc_conn_ref = NULL;
 }
 
 const struct value_string msc_a_fsm_event_names[] = {