From e30e9292f2b5ac05065a00ba8408420727f84166 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 18 Mar 2015 15:47:18 +0100 Subject: [PATCH] proper release of path structure (path_destroy() vs free()) --- server/include/path.h | 2 ++ server/src/cfg.c | 2 +- server/src/path.c | 9 +++++++++ server/src/server.c | 7 ++++--- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/server/include/path.h b/server/include/path.h index 44167e986..5867c6cc9 100644 --- a/server/include/path.h +++ b/server/include/path.h @@ -91,4 +91,6 @@ void path_stats(struct path *p); int path_print(struct path *p, char *buf, int len); +int path_destroy(struct path *p); + #endif /* _PATH_H_ */ diff --git a/server/src/cfg.c b/server/src/cfg.c index 08d9bc060..205bfe5e0 100644 --- a/server/src/cfg.c +++ b/server/src/cfg.c @@ -147,11 +147,11 @@ int config_parse_path(config_setting_t *cfg, } } else { - free(p); char buf[33]; path_print(p, buf, sizeof(buf)); warn("Path %s is not enabled", buf); + path_destroy(p); } return 0; diff --git a/server/src/path.c b/server/src/path.c index faca5b5b1..347154fa9 100644 --- a/server/src/path.c +++ b/server/src/path.c @@ -66,6 +66,7 @@ static void * path_send(void *arg) /** Receive messages */ static void * path_run(void *arg) { + char buf[33]; struct path *p = arg; struct msg *m = alloc(sizeof(struct msg)); if (!m) @@ -205,3 +206,11 @@ int path_print(struct path *p, char *buf, int len) return 0; } + +int path_destroy(struct path *p) +{ + list_destroy(&p->destinations); + list_destroy(&p->hooks); + + return 0; +} diff --git a/server/src/server.c b/server/src/server.c index e6235f24e..f9ba46162 100644 --- a/server/src/server.c +++ b/server/src/server.c @@ -38,6 +38,7 @@ static void quit() info("Stopping paths:"); for (struct path *p = paths; p; p = p->next) { INDENT path_stop(p); + path_destroy(p); } info("Stopping nodes:"); @@ -50,7 +51,7 @@ static void quit() if_stop(i); } - /** @todo Free nodes and paths */ + /** @todo Free nodes */ config_destroy(&config); @@ -155,8 +156,8 @@ int main(int argc, char *argv[]) struct path *p = paths; info("Runtime Statistics:"); - info("%12s " MAG("=>") " %-12s: %-8s %-8s %-8s %-8s %-8s", - "Source", "Destination", "#Sent", "#Recv", "#Drop", "#Skip", "#Inval"); + info("%-32s : %-8s %-8s %-8s %-8s %-8s", + "Source " MAG("=>") " Destination", "#Sent", "#Recv", "#Drop", "#Skip", "#Inval"); info("---------------------------------------------------------------------------"); while (1) {