Valgrind shows some memory leaks while launching 'df' without arguments: ==8809== LEAK SUMMARY: ==8809== definitely lost: 48 bytes in 1 blocks ==8809== indirectly lost: 16 bytes in 3 blocks ...
If I launch 'df -a' valgrind doesn't detect any 'lost' memory. As far as I understand, this is not the case for using IF_LINT macro, as it's impossible to predict the size of lost memory. I believe the following patch eliminates the leak. One more thing: the inserted code looks similar to the fragment at gnulib/lib/mountlist.c:964. What about moving this fragment to stand-alone function (free_mount_entry(struct mount_entry *me))? It implies exposing this function in mountlist.h. -- Anton >From 0ac25b9c2b1f72601b536cc92ae28aec29f6942a Mon Sep 17 00:00:00 2001 From: Anton Ovchinnikov <[email protected]> Date: Mon, 8 Jul 2013 00:03:37 +0400 Subject: [PATCH] maint: fix a memory leak in df * src/df.c (filter_mount_list): Free mount_entry with longer me_mountdir while building devlist. --- src/df.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/df.c b/src/df.c index 0515131..e2b0257 100644 --- a/src/df.c +++ b/src/df.c @@ -639,7 +639,12 @@ filter_mount_list (void) || ( strlen (devlist->me->me_mountdir) > strlen (me->me_mountdir))) { - /* FIXME: free ME - the others are also not free()d. */ + struct mount_entry *old_me = devlist->me; + free (old_me->me_devname); + free (old_me->me_mountdir); + if (old_me->me_type_malloced) + free (old_me->me_type); + free (old_me); devlist->me = me; } continue; /* ... with the loop over the mount_list. */ -- 1.8.1.4
