Hi,

When I link my code with libtcmalloc, memcheck misses a situation where 
I clearly read from an already freed memory.

Here's how to see the problem:

$ cat tt.cc
#include <iostream>
using namespace std;
main() {
   int *x = new int;
   *x = 9;
   delete x;
   cout << "got value of " << *x<< endl;
}
$ g++ tt.cc -ltcmalloc
$ ~/valgrind-3.8.1/bin/valgrind ./a.out
==6672== Memcheck, a memory error detector
==6672== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==6672== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==6672== Command: ./a.out
==6672==
got value of 0
==6672==
==6672== HEAP SUMMARY:
==6672==     in use at exit: 0 bytes in 0 blocks
==6672==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==6672==
==6672== All heap blocks were freed -- no leaks are possible
==6672==
==6672== For counts of detected and suppressed errors, rerun with: -v
==6672== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 21 from 6)


No errors.
When I do not use libtcmalloc, it is detected properly:

$ g++ tt.cc
$ ~/valgrind-3.8.1/bin/valgrind ./a.out
==6708== Memcheck, a memory error detector
==6708== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==6708== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==6708== Command: ./a.out
==6708==
==6708== Invalid read of size 4
==6708==    at 0x80486E8: main (in /tmp/a.out)
==6708==  Address 0x4311028 is 0 bytes inside a block of size 4 free'd
==6708==    at 0x402892A: operator delete(void*) (vg_replace_malloc.c:480)
==6708==    by 0x80486E3: main (in /tmp/a.out)
==6708==
got value of 9
==6708==
==6708== HEAP SUMMARY:
==6708==     in use at exit: 0 bytes in 0 blocks
==6708==   total heap usage: 1 allocs, 1 frees, 4 bytes allocated
==6708==
==6708== All heap blocks were freed -- no leaks are possible
==6708==
==6708== For counts of detected and suppressed errors, rerun with: -v
==6708== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 17 from 6)

$ ~/valgrind-3.8.1/bin/valgrind --version
valgrind-3.8.1
$ g++ --version
g++-4.6.real (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
Copyright (C) 2011 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,

--
Yuval Hager


------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to