sgsn: Cancel pending timer in sgsn_mm_ctx_free

Currently the timer is not stopped before the MM context is freed
which can lead to failure if sgsn_mm_ctx_free is called while timer
protected procedures are active.

This patch add code to cancel the timer if necessary from within
sgsn_mm_ctx_free.

Ticket: OW#1322
Sponsored-by: On-Waves ehf
diff --git a/openbsc/src/gprs/gprs_sgsn.c b/openbsc/src/gprs/gprs_sgsn.c
index ce9868e..e684713 100644
--- a/openbsc/src/gprs/gprs_sgsn.c
+++ b/openbsc/src/gprs/gprs_sgsn.c
@@ -180,6 +180,11 @@
 {
 	struct sgsn_pdp_ctx *pdp, *pdp2;
 
+	if (osmo_timer_pending(&mm->timer)) {
+		LOGMMCTXP(LOGL_INFO, mm, "Cancelling MM timer %u\n", mm->T);
+		osmo_timer_del(&mm->timer);
+	}
+
 	/* Unlink from global list of MM contexts */
 	llist_del(&mm->list);