From 5b0eb9bd95a72a24f8ca1c2bb776c8e5596ff42f Mon Sep 17 00:00:00 2001 From: Niclas Hofmann Date: Wed, 15 Aug 2018 14:01:33 +0200 Subject: [PATCH] Memory leak fixed for printpath routine checked with `du -k /etc | valgrind --leak-check=full --show-leak-kinds=all ./xdu` --- xdu.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/xdu.c b/xdu.c index f8e6a12..434c1da 100644 --- a/xdu.c +++ b/xdu.c @@ -696,17 +696,21 @@ void printpath(int x, int y) { struct node *np; char* path; + char* tmp_path; np = findnode(&top, x, y); if (np == NULL) return; - path = np->name; + asprintf(&path, "%s", np->name); while(np->parent != NULL) { + tmp_path = path; asprintf(&path, "%s/%s", np->parent->name, path); np = np->parent; + free(tmp_path); } - path += 6; - printf("%s\n", path); + tmp_path = path + 6; + printf("%s\n", tmp_path); + free(path); } void reset(void)