|
From: Ganapathy V. <gan...@ya...> - 2013-04-03 12:59:34
|
Hi,
I am trying out a sample program that has two issues
1. A memory leak
2. A free memory access
Following is my source code
#include <stdio.h>
int main()
{
int *p = malloc(sizeof(int));
p = malloc(sizeof(int));
free(p);
*p = 5;
return 0;
}
I have compiled this code with the arm linux cross compiler (ofcourse with -g). When I executed this with valgrind I got the following output
For the invalid memory access it shows the faulting point, however it does not show the location where the memory was freed. Similarly, while indicating the memory leak, it does not show the point of allocation. It just shows the heap address that was lost. Can you tell me why valgrind is not able to trace the points of allocation and de-allocation of memory? It doesn't seem to be an issue with debug symbols, as its able to point out invalid memory access correctly. I would appreciate any help on this.
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --track-origins=yes --num-callers=20 ./a.out
==1563== Memcheck, a memory error detector
==1563== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==1563== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==1563== Command: ./a.out
==1563==
==1563== Conditional jump or move depends on uninitialised value(s)
==1563== at 0x4016514: index (in /lib/ld-2.9.so)
==1563== Uninitialised value was created by a stack allocation
==1563== at 0x40020E0: dl_main (in /lib/ld-2.9.so)
==1563==
==1563== Invalid write of size 4
==1563== at 0x83F0: main (sample.c:8)
==1563== Address 0x4973060 is 0 bytes inside a block of size 4 free'd
==1563== at 0x4832B68: free (in /usr/lib/valgrind/vgpreload_memcheck-arm-linux.so)
==1563==
==1563==
==1563== HEAP SUMMARY:
==1563== in use at exit: 4 bytes in 1 blocks
==1563== total heap usage: 2 allocs, 1 frees, 8 bytes allocated
==1563==
==1563== 4 bytes in 1 blocks are definitely lost in loss record 1 of 1
==1563== at 0x48332D0: malloc (in /usr/lib/valgrind/vgpreload_memcheck-arm-linux.so)
==1563==
==1563== LEAK SUMMARY:
==1563== definitely lost: 4 bytes in 1 blocks
==1563== indirectly lost: 0 bytes in 0 blocks
==1563== possibly lost: 0 bytes in 0 blocks
==1563== still reachable: 0 bytes in 0 blocks
==1563== suppressed: 0 bytes in 0 blocks
==1563==
==1563== For counts of detected and suppressed errors, rerun with: -v
==1563== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 13 from 5)
Regards,
- Vijay |
|
From: David F. <fa...@kd...> - 2013-04-03 13:13:21
|
On Wednesday 03 April 2013 20:59:23 Ganapathy Vijay wrote: > I have compiled this code with the arm linux cross compiler (ofcourse with > -g). Did you also disable optimizations? Make sure -O2 isn't in there. Otherwise the call to free() can get inlined, for instance. -- David Faure, fa...@kd..., http://www.davidfaure.fr Working on KDE, in particular KDE Frameworks 5 |
|
From: Ganapathy V. <gan...@ya...> - 2013-04-04 04:31:25
|
Yes. I did not enable any level of compiler optimization. ________________________________ From: David Faure <fa...@kd...> To: val...@li...; Ganapathy Vijay <gan...@ya...> Sent: Wednesday, 3 April 2013 6:47 PM Subject: Re: [Valgrind-users] Fw: valgrind on armv71 does not show point of allocation and deallocation On Wednesday 03 April 2013 20:59:23 Ganapathy Vijay wrote: > I have compiled this code with the arm linux cross compiler (ofcourse with > -g). Did you also disable optimizations? Make sure -O2 isn't in there. Otherwise the call to free() can get inlined, for instance. -- David Faure, fa...@kd..., http://www.davidfaure.fr Working on KDE, in particular KDE Frameworks 5 |