osmux: Fix memleak on error code path

Change-Id: Ib84f78a53293799b925b645156513e129c32c705
diff --git a/src/libosmo-mgcp/mgcp_osmux.c b/src/libosmo-mgcp/mgcp_osmux.c
index b635aef..4d1ec72 100644
--- a/src/libosmo-mgcp/mgcp_osmux.c
+++ b/src/libosmo-mgcp/mgcp_osmux.c
@@ -192,6 +192,12 @@
 	int ret;
 	struct msgb *msg;
 
+	if (conn->osmux.state != OSMUX_STATE_ENABLED) {
+		LOGPCONN(conn->conn, DOSMUX, LOGL_INFO, "forwarding RTP to Osmux conn not yet enabled, dropping (cid=%d)\n",
+		conn->osmux.cid);
+		return -1;
+	}
+
 	msg = msgb_alloc(4096, "RTP");
 	if (!msg)
 		return -1;
@@ -199,12 +205,6 @@
 	memcpy(msg->data, buf, buf_len);
 	msgb_put(msg, buf_len);
 
-	if (conn->osmux.state != OSMUX_STATE_ENABLED) {
-		LOGPCONN(conn->conn, DOSMUX, LOGL_INFO, "forwarding RTP to Osmux conn not yet enabled, dropping (cid=%d)\n",
-		conn->osmux.cid);
-		return -1;
-	}
-
 	while ((ret = osmux_xfrm_input(conn->osmux.in, msg, conn->osmux.cid)) > 0) {
 		/* batch full, build and deliver it */
 		osmux_xfrm_input_deliver(conn->osmux.in);