[FS#4222] valgrind: does not detect memory leaks depite unstripped libraries

OpenWrt Bugs openwrt-bugs at lists.openwrt.org
Sun Jan 9 09:34:30 PST 2022


THIS IS AN AUTOMATED MESSAGE, DO NOT REPLY.

A new Flyspray task has been opened.  Details are below. 

User who did this - MikePetullo (MikePetullo) 

Attached to Project - OpenWrt/LEDE Project
Summary - valgrind: does not detect memory leaks depite unstripped libraries
Task Type - Bug Report
Category - Base system
Status - Unconfirmed
Assigned To - 
Operating System - All
Severity - Low
Priority - Very Low
Reported Version - Trunk
Due in Version - Undecided
Due Date - Undecided
Details - I am using valgrind 3.18.1-1 on x86_64 r18400-f9782f5bcd. This build uses musl 1.2.2-3. My libraries, to include libc, are not stripped.

According to the upstream bug at https://bugs.kde.org/show_bug.cgi?id=435441, changes to musl left valgrind unable to detect memory leaks. The workaround proposed in that bug report, namely passing "--soname-synonyms=somalloc=NONE" to valgrind, seems to fix the problem on OpenWrt.

Here is an example program:


#include 
#include 
                   
int f(void) {
        char *buf = malloc(BUFSIZ);
        if (buf == NULL) {         
                return -1;
        }                 
        return 0;
}                           
                            
int main(void)   
{             
        f();  
}

I compiled this with "gcc -O0 -o test test.c", and I ran the following to demonstrate the problem and workaround:

$ valgrind --leak-check=full ./test
==31728== Memcheck, a memory error detector
==31728== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==31728== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==31728== Command: ./test
==31728== 
==31728== 
==31728== HEAP SUMMARY:
==31728==     in use at exit: 0 bytes in 0 blocks
==31728==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==31728== 
==31728== All heap blocks were freed -- no leaks are possible
==31728== 
==31728== For lists of detected and suppressed errors, rerun with: -s
==31728== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
$ valgrind --leak-check=full  --soname-synonyms=somalloc=NONE ./test
==31732== Memcheck, a memory error detector
==31732== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==31732== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==31732== Command: ./test
==31732== 
==31732== 
==31732== HEAP SUMMARY:
==31732==     in use at exit: 1,024 bytes in 1 blocks
==31732==   total heap usage: 1 allocs, 0 frees, 1,024 bytes allocated
==31732== 
==31732== 1,024 bytes in 1 blocks are definitely lost in loss record 1 of 1
==31732==    at 0x48806B6: malloc (vg_replace_malloc.c:381)
==31732==    by 0x40111B: f (in /home/mike at flyn.org/valgrindC/test)
==31732==    by 0x40113D: main (in /home/mike at flyn.org/valgrindC/test)
==31732== 
==31732== LEAK SUMMARY:
==31732==    definitely lost: 1,024 bytes in 1 blocks
==31732==    indirectly lost: 0 bytes in 0 blocks
==31732==      possibly lost: 0 bytes in 0 blocks
==31732==    still reachable: 0 bytes in 0 blocks
==31732==         suppressed: 0 bytes in 0 blocks
==31732== 
==31732== For lists of detected and suppressed errors, rerun with: -s
==31732== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)


More information can be found at the following URL:
https://bugs.openwrt.org/index.php?do=details&task_id=4222

You are receiving this message because you have requested it from the Flyspray bugtracking system.  If you did not expect this message or don't want to receive mails in future, you can change your notification settings at the URL shown above.



More information about the openwrt-bugs mailing list