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;
diff --git a/libmctp.h b/libmctp.h
index 69ec46a..0a40c0e 100644
--- a/libmctp.h
+++ b/libmctp.h
@@ -60,6 +60,7 @@
struct mctp_bus;
struct mctp *mctp_init(void);
+void mctp_destroy(struct mctp *mctp);
/* Register a binding to the MCTP core, and creates a bus (populating
* binding->bus).