|
From: Konstantin S. <kon...@gm...> - 2010-05-07 14:37:02
|
Hi,
The code in die_and_free_mem (memcheck/mc_malloc_wrappers.c) is:
/* Put it out of harm's way for a while, if not from a client request */
if (MC_AllocCustom != mc->allockind) {
/* Record where freed */
mc->where = VG_(record_ExeContext) ( tid, 0/*first_ip_delta*/ );
add_to_freed_queue ( mc );
} else {
VG_(free) ( mc );
}
So, if I allocate a chunk of memory, free it and then access, I get a
warning like this:
--------------------------------------------------------------------------------
Invalid read of size 4
<STACK>
Address 0xb00601f34 is 20 bytes inside a block of size 40 free'd
<STACK>
--------------------------------------------------------------------------------
If I have a custom allocator which is annotated
with VALGRIND_{MALLOCLIKE,FREELIKE}_BLOCK, I get a much less informative
report:
--------------------------------------------------------------------------------
Invalid read of size 4
<STACK>
Address 0xb00601f34 is not stack'd, malloc'd or (recently) free'd
--------------------------------------------------------------------------------
Why?
I get what I need If I change the code in die_and_free_mem to simply this:
mc->where = VG_(record_ExeContext) ( tid, 0/*first_ip_delta*/ );
add_to_freed_queue ( mc );
Is there a reason not to do this?
Thanks,
--kcc
|