From 9c9dc35f1329f03d22c1254cf8a6c7bc3ad3a9c8 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Tue, 13 Mar 2012 09:11:01 +0100 Subject: [PATCH] Clean up dynamic fields when closing a port. In the course of development we added more and more allocations into the port code without freeing them on close. We do not yet call the close function, so there was never an issue. Once we start to reset the ports, to clear faults for example, then we will need this. Signed-off-by: Richard Cochran --- port.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/port.c b/port.c index d4449ee..01d3c55 100644 --- a/port.c +++ b/port.c @@ -246,6 +246,16 @@ static int add_foreign_master(struct port *p, struct ptp_message *m) return broke_threshold || diff; } +static void free_foreign_masters(struct port *p) +{ + struct foreign_clock *fc; + while ((fc = LIST_FIRST(&p->foreign_masters)) != NULL) { + LIST_REMOVE(fc, list); + fc_clear(fc); + free(fc); + } +} + static int port_clr_tmo(int fd) { struct itimerspec tmo = { @@ -782,6 +792,15 @@ static void process_sync(struct port *p, struct ptp_message *m) void port_close(struct port *p) { int i; + + if (p->last_follow_up) + msg_put(p->last_follow_up); + if (p->last_sync) + msg_put(p->last_sync); + if (p->delay_req) + msg_put(p->delay_req); + + free_foreign_masters(p); transport_close(p->trp, &p->fda); transport_destroy(p->trp); for (i = 0; i < N_TIMER_FDS; i++) {