[Valgrind-users] Fw: valgrind on armv71 does not show point of allocation and deallocation

2013-04-03 Thread Ganapathy Vijay
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--
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire 
the most talented Cisco Certified professionals. Visit the 
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] Fw: valgrind on armv71 does not show point of allocation and deallocation

2013-04-03 Thread David Faure
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...@kde.org, http://www.davidfaure.fr
Working on KDE, in particular KDE Frameworks 5


--
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire 
the most talented Cisco Certified professionals. Visit the 
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] Fw: valgrind on armv71 does not show point of allocation and deallocation

2013-04-03 Thread Ganapathy Vijay
Yes. I did not enable any level of compiler optimization.


 From: David Faure fa...@kde.org
To: valgrind-users@lists.sourceforge.net; Ganapathy Vijay 
ganapathy_vi...@yahoo.com 
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...@kde.org, http://www.davidfaure.fr
Working on KDE, in particular KDE Frameworks 5--
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire 
the most talented Cisco Certified professionals. Visit the 
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users