trans_free: tear down conn when last transaction is done

In trans_free(), call subscr_conn_release_when_unused(), so that we are sure to
clean up after the last transaction is done.

This fixes an error where a conn lingered after a CC failure, because that code
path forgot to trigger cleanup.

Rationale: so far we were triggering the release check after each DTAP dispatch
(compl_l3 and "normal" DTAP), which is sufficient for properly closed
transactions. We also need a check for when a timeout clears an erratic trans.

Adjust test expectation of test_call_mo_to_unknown_timeout to show that the
error is now fixed.

msc_vlr_test_reject_concurrency now sees an additional release checking event
when the SMS transaction is done, which is expected and does not affect the
test otherwise.

Related: OS#2779
Change-Id: I46ff2e9b09b67e4e0d79cccf8c04936f17281fcb
diff --git a/src/libmsc/transaction.c b/src/libmsc/transaction.c
index cdaba9c..4a3b064 100644
--- a/src/libmsc/transaction.c
+++ b/src/libmsc/transaction.c
@@ -117,6 +117,7 @@
 void trans_free(struct gsm_trans *trans)
 {
 	enum msc_subscr_conn_use conn_usage_token = MSC_CONN_USE_UNTRACKED;
+	struct gsm_subscriber_connection *conn;
 
 	switch (trans->protocol) {
 	case GSM48_PDISC_CC:
@@ -153,8 +154,15 @@
 	if (trans->conn)
 		msc_subscr_conn_put(trans->conn, conn_usage_token);
 
+	conn = trans->conn;
 	trans->conn = NULL;
 	talloc_free(trans);
+
+	/* trans_free() should always happen while the conn_fsm is still around. */
+	OSMO_ASSERT(conn->conn_fsm);
+
+	/* Possibly this was the last transaction used by this conn. */
+	subscr_conn_release_when_unused(conn);
 }
 
 /*! allocate an unused transaction ID for the given subscriber