Fix LAPD UA message buffer memory leak.

The state check in lapd_dl_reset causes some buffers
never to be released. Using talloc report LAPD UA
message buffers are never released after each call
and cause a memory leak.

Change-Id: I2799b70623f2ec4dbc725eb213e332e98da02a3e
diff --git a/src/gsm/lapd_core.c b/src/gsm/lapd_core.c
index 0cc28a6..a602d78 100644
--- a/src/gsm/lapd_core.c
+++ b/src/gsm/lapd_core.c
@@ -308,11 +308,6 @@
 /* reset to IDLE state */
 void lapd_dl_reset(struct lapd_datalink *dl)
 {
-	if (dl->state == LAPD_STATE_IDLE)
-		return;
-	LOGP(DLLAPD, LOGL_INFO, "Resetting LAPDm instance (dl=%p)\n", dl);
-	/* enter idle state (and remove eventual cont_res) */
-	lapd_dl_newstate(dl, LAPD_STATE_IDLE);
 	/* flush buffer */
 	lapd_dl_flush_tx(dl);
 	lapd_dl_flush_send(dl);
@@ -322,6 +317,11 @@
 	/* stop Timers */
 	lapd_stop_t200(dl);
 	lapd_stop_t203(dl);
+	if (dl->state == LAPD_STATE_IDLE)
+		return;
+	LOGP(DLLAPD, LOGL_INFO, "Resetting LAPDm instance (dl=%p)\n", dl);
+	/* enter idle state (and remove eventual cont_res) */
+	lapd_dl_newstate(dl, LAPD_STATE_IDLE);
 }
 
 /* reset and de-allocate history buffer */