libmctp: Add mctp_destroy()

Provide an abstraction to clean up memory to avoid false-positives with
leak sanitizers.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Id0f03ec61fcaf6eb0ed27e8f735720f1ea7e5e8e
diff --git a/core.c b/core.c
index 52961fd..34bd75a 100644
--- a/core.c
+++ b/core.c
@@ -237,6 +237,21 @@
 	return mctp;
 }
 
+void mctp_destroy(struct mctp *mctp)
+{
+	int i;
+
+	/* Cleanup message assembly contexts */
+	for (i = 0; i < ARRAY_SIZE(mctp->msg_ctxs); i++) {
+		struct mctp_msg_ctx *tmp = &mctp->msg_ctxs[i];
+		if (tmp->buf)
+			__mctp_free(tmp->buf);
+	}
+
+	__mctp_free(mctp->busses);
+	__mctp_free(mctp);
+}
+
 int mctp_set_rx_all(struct mctp *mctp, mctp_rx_fn fn, void *data)
 {
 	mctp->message_rx = fn;