core: Introduce mctp_bus_destroy()

Tearing down a binding needs to free all packets that have been queued
but not yet transmitted.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Ia4bff3243f80e1088c521b09a512584383deb1ad
diff --git a/core.c b/core.c
index 8a2b899..7f3d96a 100644
--- a/core.c
+++ b/core.c
@@ -262,6 +262,16 @@
 	mctp->max_message_size = message_size;
 }
 
+static void mctp_bus_destroy(struct mctp_bus *bus)
+{
+	while (bus->tx_queue_head) {
+		struct mctp_pktbuf *curr = bus->tx_queue_head;
+
+		bus->tx_queue_head = curr->next;
+		mctp_pktbuf_free(curr);
+	}
+}
+
 void mctp_destroy(struct mctp *mctp)
 {
 	size_t i;
@@ -274,6 +284,9 @@
 			__mctp_free(tmp->buf);
 	}
 
+	while (mctp->n_busses--)
+		mctp_bus_destroy(&mctp->busses[mctp->n_busses]);
+
 	__mctp_free(mctp->busses);
 	__mctp_free(mctp);
 }