Skip to content

valgrind does not detect actual memory leaks at all #5

@fzyzcjy

Description

@fzyzcjy

Hi thanks for the lib! But it does not work imho...

Sample rust code (but you can use C++ to reproduce, of course):

    println!("creating a bad_vec which has memory leak!");
    let bad_vec = vec![0u8; 1024 * 1024];
    std::mem::forget(bad_vec);

build it, then run it:

cargo build --target armeabi-v7a

adb push target/armv7-linux-androideabi/debug/vision_utils_rs /data/local/tmp/vision_utils_rs

adb shell /data/local/tmp/valgrind/bin/valgrind /data/local/tmp/vision_utils_rs

outputs are as follows. Need to compare with #4 (the "outputs of a huawei phone" section). After comparsion, we can see that, it detects nothing even though there is a memory leak...

==11542== Memcheck, a memory error detector
==11542== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==11542== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==11542== Command: /data/local/tmp/vision_utils_rs
==11542== 
WARNING: linker: /data/local/tmp/valgrind/lib/valgrind/vgpreload_core-arm-linux.so: unsupported flags DT_FLAGS_1=0x421
WARNING: linker: /data/local/tmp/valgrind/lib/valgrind/vgpreload_memcheck-arm-linux.so: unsupported flags DT_FLAGS_1=0x421
==11542== Invalid free() / delete / delete[] / realloc()
==11542==    at 0x4858580: free (in /data/local/tmp/valgrind/lib/valgrind/vgpreload_memcheck-arm-linux.so)
==11542==  Address 0x484a20c is in a rw- anonymous segment
==11542== 
==11542== Invalid read of size 1
==11542==    at 0x400AB04: __dl_memcmp (in /system/bin/linker)
==11542==    by 0xFE932253: ???
==11542==  Address 0x4866000 is 3,824 bytes inside a block of size 4,096 free'd
==11542==    at 0x4858580: ??? (in /data/local/tmp/valgrind/lib/valgrind/vgpreload_memcheck-arm-linux.so)
==11542==  Block was alloc'd at
==11542==    at 0x485686C: ??? (in /data/local/tmp/valgrind/lib/valgrind/vgpreload_memcheck-arm-linux.so)
==11542== 
invalid pointer 0x4866140 (page signature mismatch)
==11542== 
==11542== HEAP SUMMARY:
==11542==     in use at exit: 120 bytes in 3 blocks
==11542==   total heap usage: 5 allocs, 4 frees, 8,312 bytes allocated
==11542== 
==11542== LEAK SUMMARY:
==11542==    definitely lost: 0 bytes in 0 blocks
==11542==    indirectly lost: 0 bytes in 0 blocks
==11542==      possibly lost: 0 bytes in 0 blocks
==11542==    still reachable: 120 bytes in 3 blocks
==11542==         suppressed: 0 bytes in 0 blocks
==11542== Rerun with --leak-check=full to see details of leaked memory
==11542== 
==11542== For lists of detected and suppressed errors, rerun with: -s
==11542== ERROR SUMMARY: 3 errors from 2 contexts (suppressed: 0 from 0)

If needed, here is a more detailed output:

Details
(base) ➜  rust git:(master) ✗ adb shell /data/local/tmp/valgrind/bin/valgrind -s --leak-check=full  --show-leak-kinds=all /data/local/tmp/vision_utils_rs
==11574== Memcheck, a memory error detector
==11574== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==11574== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==11574== Command: /data/local/tmp/vision_utils_rs
==11574== 
WARNING: linker: /data/local/tmp/valgrind/lib/valgrind/vgpreload_core-arm-linux.so: unsupported flags DT_FLAGS_1=0x421
WARNING: linker: /data/local/tmp/valgrind/lib/valgrind/vgpreload_memcheck-arm-linux.so: unsupported flags DT_FLAGS_1=0x421
==11574== Invalid free() / delete / delete[] / realloc()
==11574==    at 0x4858580: free (in /data/local/tmp/valgrind/lib/valgrind/vgpreload_memcheck-arm-linux.so)
==11574==  Address 0x484a20c is in a rw- anonymous segment
==11574== 
==11574== Invalid read of size 1
==11574==    at 0x400AB04: __dl_memcmp (in /system/bin/linker)
==11574==    by 0xFECDB253: ???
==11574==  Address 0x4866000 is 3,824 bytes inside a block of size 4,096 free'd
==11574==    at 0x4858580: ??? (in /data/local/tmp/valgrind/lib/valgrind/vgpreload_memcheck-arm-linux.so)
==11574==  Block was alloc'd at
==11574==    at 0x485686C: ??? (in /data/local/tmp/valgrind/lib/valgrind/vgpreload_memcheck-arm-linux.so)
==11574== 
invalid pointer 0x4866140 (page signature mismatch)
==11574== 
==11574== HEAP SUMMARY:
==11574==     in use at exit: 120 bytes in 3 blocks
==11574==   total heap usage: 5 allocs, 4 frees, 8,312 bytes allocated
==11574== 
==11574== 120 bytes in 3 blocks are still reachable in loss record 1 of 1
==11574==    at 0x485686C: ??? (in /data/local/tmp/valgrind/lib/valgrind/vgpreload_memcheck-arm-linux.so)
==11574== 
==11574== LEAK SUMMARY:
==11574==    definitely lost: 0 bytes in 0 blocks
==11574==    indirectly lost: 0 bytes in 0 blocks
==11574==      possibly lost: 0 bytes in 0 blocks
==11574==    still reachable: 120 bytes in 3 blocks
==11574==         suppressed: 0 bytes in 0 blocks
==11574== 
==11574== ERROR SUMMARY: 3 errors from 2 contexts (suppressed: 0 from 0)
==11574== 
==11574== 1 errors in context 1 of 2:
==11574== Invalid read of size 1
==11574==    at 0x400AB04: __dl_memcmp (in /system/bin/linker)
==11574==    by 0xFECDB253: ???
==11574==  Address 0x4866000 is 3,824 bytes inside a block of size 4,096 free'd
==11574==    at 0x4858580: ??? (in /data/local/tmp/valgrind/lib/valgrind/vgpreload_memcheck-arm-linux.so)
==11574==  Block was alloc'd at
==11574==    at 0x485686C: ??? (in /data/local/tmp/valgrind/lib/valgrind/vgpreload_memcheck-arm-linux.so)
==11574== 
==11574== 
==11574== 2 errors in context 2 of 2:
==11574== Invalid free() / delete / delete[] / realloc()
==11574==    at 0x4858580: ??? (in /data/local/tmp/valgrind/lib/valgrind/vgpreload_memcheck-arm-linux.so)
==11574==  Address 0x484a20c is in a rw- anonymous segment
==11574== 
==11574== ERROR SUMMARY: 3 errors from 2 contexts (suppressed: 0 from 0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions