Hello All,
I have used a sample C program which doesn't free allocated heap memory during process stop. Tried Valgrind to see any leaks reporting.But no leaks eventhough there are possible leaks.
Expecting some help/directions on what could be missing to get the leak report.
Below are my code, compiler used along with Valgrind.
Code:
char *ptr = NULL; printf("Doing memory alloc\n"); ptr = malloc(100); if (!ptr) { printf("Malloc failure\n"); return -1; } memset(ptr, 0, 50); strcpy(ptr, "Valgrind leak Analysis!!!\n"); printf("%s\n", ptr); return 0;
Valgrind output:
root@Bean10:/home/superadmin# valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose ./leaks
==13587== Memcheck, a memory error detector
==13587== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==13587== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info
==13587== Command: ./leaks
==13587==
.....
--13587-- Contents of /proc/version:
--13587-- Linux version 5.4.164 (renv@bbd-svr-ubt20-004) (gcc version 7.5.0 (OpenWrt GCC 7.5.0 r11-afafb2b1c)) #0 SMP PREEMPT Mon Jun 5 15:00:29 2023
--13587--
--13587-- Arch and hwcaps: ARM64, LittleEndian, baseline
--13587-- Page sizes: currently 4096, max supported 65536
--13587-- Valgrind library directory: /usr/lib/valgrind
--13587-- Reading syms from /home/superadmin/leaks
....
Doing memory alloc
Valgrind leak Analysis!!!
....
==13587==
==13587== HEAP SUMMARY:
==13587== in use at exit: 0 bytes in 0 blocks
==13587== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==13587==
==13587== All heap blocks were freed -- no leaks are possible
==13587==
==13587== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Below are the cross compiler used and version details:
aarch64-openwrt-linux-musl-gcc -g leaks.c
aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 7.5.0 r11-afafb2b1c) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Thanks in Advance..