transport: mctp-demux: Use a common cleanup path in *_recv()

Previously the error paths were all individually freeing the
heap-allocated message data buffer. Provide a common path instead, as
we will soon add another error path to the implementation.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I3356cc503cf774f68237548b79a9a0b0d76134d7
diff --git a/src/transport/mctp-demux.c b/src/transport/mctp-demux.c
index abbe8d6..dc5e2d2 100644
--- a/src/transport/mctp-demux.c
+++ b/src/transport/mctp-demux.c
@@ -117,6 +117,7 @@
 	struct pldm_transport_mctp_demux *demux = transport_to_demux(t);
 	size_t mctp_prefix_len = 2;
 	struct msghdr msg = { 0 };
+	pldm_requester_rc_t res;
 	uint8_t mctp_prefix[2];
 	struct iovec iov[2];
 	mctp_eid_t eid = 0;
@@ -147,8 +148,8 @@
 	if (length < min_len) {
 		/* read and discard */
 		recv(demux->socket, buf, length, 0);
-		free(buf);
-		return PLDM_REQUESTER_INVALID_RECV_LEN;
+		res = PLDM_REQUESTER_INVALID_RECV_LEN;
+		goto cleanup_buf;
 	}
 
 	pldm_len = length - mctp_prefix_len;
@@ -162,19 +163,24 @@
 
 	bytes = recvmsg(demux->socket, &msg, 0);
 	if (length != bytes) {
-		free(buf);
-		return PLDM_REQUESTER_INVALID_RECV_LEN;
+		res = PLDM_REQUESTER_INVALID_RECV_LEN;
+		goto cleanup_buf;
 	}
 
 	if ((mctp_prefix[0] != eid) || (mctp_prefix[1] != mctp_msg_type)) {
-		free(buf);
-		return PLDM_REQUESTER_NOT_PLDM_MSG;
+		res = PLDM_REQUESTER_NOT_PLDM_MSG;
+		goto cleanup_buf;
 	}
 
 	*pldm_msg = buf;
 	*msg_len = pldm_len;
 
 	return PLDM_REQUESTER_SUCCESS;
+
+cleanup_buf:
+	free(buf);
+
+	return res;
 }
 
 static pldm_requester_rc_t