Subject: Re: bug#12542: [PATCH] du: avoid abort on systems for which ->me_type is not malloc'd

From: Bernhard Voelker <[email-masked]>
Date: Sun, 30 Sep 2012 18:12:12 +0200

On 09/30/2012 02:43 PM, Jim Meyering wrote:
> A better one should come soon, in which I add
> a function in mountlist.c (declared in the .h file)
> by which to encapsulate this mount-entry freeing process.

Good idea - also df doesn't free the mount_list:

valgrind --leak-check=full --show-reachable=yes src/df /
==3835== Memcheck, a memory error detector
==3835== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==3835== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==3835== Command: src/df /
==3835==
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1       12095032 7434584   4046048  65% /
==3835==
==3835== HEAP SUMMARY:
==3835==     in use at exit: 3,013 bytes in 149 blocks
==3835==   total heap usage: 657 allocs, 508 frees, 41,101 bytes allocated
==3835==
==3835== 144 bytes in 1 blocks are still reachable in loss record 1 of 5
==3835==    at 0x4C297CD: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==3835==    by 0x40A1B8: xmalloc (xmalloc.c:43)
==3835==    by 0x402F90: main (xalloc.h:113)
==3835==
==3835== 254 bytes in 37 blocks are still reachable in loss record 2 of 5
==3835==    at 0x4C297CD: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==3835==    by 0x40A1B8: xmalloc (xmalloc.c:43)
==3835==    by 0x40A2CB: xmemdup (xmalloc.c:115)
==3835==    by 0x40AE8E: read_file_system_list (mountlist.c:420)
==3835==    by 0x4028F8: main (df.c:1097)
==3835==
==3835== 292 bytes in 37 blocks are still reachable in loss record 3 of 5
==3835==    at 0x4C297CD: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==3835==    by 0x40A1B8: xmalloc (xmalloc.c:43)
==3835==    by 0x40A2CB: xmemdup (xmalloc.c:115)
==3835==    by 0x40AE75: read_file_system_list (mountlist.c:418)
==3835==    by 0x4028F8: main (df.c:1097)
==3835==
==3835== 547 bytes in 37 blocks are still reachable in loss record 4 of 5
==3835==    at 0x4C297CD: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==3835==    by 0x40A1B8: xmalloc (xmalloc.c:43)
==3835==    by 0x40A2CB: xmemdup (xmalloc.c:115)
==3835==    by 0x40AE81: read_file_system_list (mountlist.c:419)
==3835==    by 0x4028F8: main (df.c:1097)
==3835==
==3835== 1,776 bytes in 37 blocks are still reachable in loss record 5 of 5
==3835==    at 0x4C297CD: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==3835==    by 0x40A1B8: xmalloc (xmalloc.c:43)
==3835==    by 0x40AE69: read_file_system_list (mountlist.c:417)
==3835==    by 0x4028F8: main (df.c:1097)
==3835==
==3835== LEAK SUMMARY:
==3835==    definitely lost: 0 bytes in 0 blocks
==3835==    indirectly lost: 0 bytes in 0 blocks
==3835==      possibly lost: 0 bytes in 0 blocks
==3835==    still reachable: 3,013 bytes in 149 blocks
==3835==         suppressed: 0 bytes in 0 blocks
==3835==
==3835== For counts of detected and suppressed errors, rerun with: -v
==3835== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 6)

The first one can be covered by "IF_LINT ( free (columns));",
but the others come from calling read_file_system_list().

Free()ing the memory should of course be guarded by IF_LINT, too.

Have a nice day,
Berny