From 4e35931bc81a5e78f88e7561ba287f384e2648d3 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sat, 31 Mar 2018 11:32:55 -0700 Subject: [PATCH] phc2sys: Clean up before exiting. Valgrind complains about memory leaks, none of which are serious. This patch frees the allocations on exit, so that any future *real* memory leaks will be obvious in the valgrind report. Signed-off-by: Richard Cochran --- phc2sys.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/phc2sys.c b/phc2sys.c index 5c54055..3a82cfe 100644 --- a/phc2sys.c +++ b/phc2sys.c @@ -262,11 +262,37 @@ static struct clock *clock_add(struct node *node, char *device) static void clock_cleanup(struct node *node) { - struct clock *c; + struct clock *c, *tmp; - LIST_FOREACH(c, &node->clocks, list) { - if (c->device) + LIST_FOREACH_SAFE(c, &node->clocks, list, tmp) { + if (c->servo) { + servo_destroy(c->servo); + } + if (c->sanity_check) { + clockcheck_destroy(c->sanity_check); + } + if (c->delay_stats) { + stats_destroy(c->delay_stats); + } + if (c->freq_stats) { + stats_destroy(c->freq_stats); + } + if (c->offset_stats) { + stats_destroy(c->offset_stats); + } + if (c->device) { free(c->device); + } + free(c); + } +} + +static void port_cleanup(struct node *node) +{ + struct port *p, *tmp; + + LIST_FOREACH_SAFE(p, &node->ports, list, tmp) { + free(p); } } @@ -1582,7 +1608,9 @@ end: if (node.pmc) close_pmc(&node); clock_cleanup(&node); + port_cleanup(&node); config_destroy(cfg); + msg_cleanup(); return r; bad_usage: usage(progname);