From 577d34facf2254edb492ae502c4ef6fdddbc9373 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Mon, 27 Aug 2012 21:09:10 +0200 Subject: [PATCH] Provide a method to release the message cache. Signed-off-by: Richard Cochran --- clock.c | 1 + msg.c | 12 ++++++++++++ msg.h | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/clock.c b/clock.c index d0c6d9c..b3e5096 100644 --- a/clock.c +++ b/clock.c @@ -99,6 +99,7 @@ static void clock_destroy(struct clock *c) servo_destroy(c->servo); mave_destroy(c->avg_delay); memset(c, 0, sizeof(*c)); + msg_cleanup(); } static int clock_fault_timeout(struct clock *c, int index, int set) diff --git a/msg.c b/msg.c index d24fbc0..3ccff96 100644 --- a/msg.c +++ b/msg.c @@ -23,6 +23,7 @@ #include +#include "contain.h" #include "msg.h" #include "print.h" #include "tlv.h" @@ -230,6 +231,17 @@ struct ptp_message *msg_allocate(void) return m; } +void msg_cleanup(void) +{ + struct message_storage *s; + struct ptp_message *m; + while ((m = TAILQ_FIRST(&msg_pool)) != NULL) { + TAILQ_REMOVE(&msg_pool, m, list); + s = container_of(m, struct message_storage, msg); + free(s); + } +} + void msg_get(struct ptp_message *m) { m->refcnt++; diff --git a/msg.h b/msg.h index b01f086..940e790 100644 --- a/msg.h +++ b/msg.h @@ -260,6 +260,11 @@ static inline int msg_type(struct ptp_message *m) */ struct ptp_message *msg_allocate(void); +/** + * Release all of the memory in the message cache. + */ +void msg_cleanup(void); + /** * Obtain a reference to a message, increasing its reference count by one. * @param m A message obtained using @ref msg_allocate().