|
From: Wedig, K. <kat...@lm...> - 2005-03-02 16:12:42
|
I apologize for posting a bug report here, but I can't get to Bugzilla.
When a client-managed memory area is allocated with new or malloc, the client
management routines are instrumented with VALGRIND_MALLOCLIKE_BLOCK and
VALGRIND_FREELIKE_BLOCK, and addrcheck is run with --leak-check=yes, addrcheck
crashes. Also, memcheck crashes in the same circumstances.
System information:
valgrind version 2.2.0
Red Hat Linux 8.0
gcc version 3.2
glibc version 2.3.2
Attached is a test program that demonstrates the bug. The program was compiled as follows:
g++ -g -Wall -fcheck-new -I../tools/valgrind-2.2.0/include/valgrind valgrind_test.cc -o valgrind
After the test program is the output of addrcheck when run as follows:
valgrind --tool=addrcheck --leak-check=yes
------------------------------------------------------------------------------
// valgrind_test.cc
// Compiled with:
// g++ -g -Wall -fcheck-new -I../tools/valgrind-2.2.0/include/valgrind valgrind_test.cc -o valgrind_test
//
// gcc --version
// gcc (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
//
// uname -a
// Linux pc2500 2.4.25 #2 SMP Thu Feb 10 14:11:11 EST 2005 i686 i686 i386 GNU/Linux
//
// rpm -q glibc
// glibc-2.3.2-4.80.8
//
// valgrind --version
// valgrind-2.2.0
//
// Executed with:
// valgrind --tool=addrcheck --leak-check=yes valgrind_test
//
#include <stdlib.h>
#include <stdio.h>
#include "valgrind.h"
#include "memcheck.h"
// Cheesy fake allocator
const int POOL_SIZE = 32000;
const int RED_ZONE_SIZE = 0;
void* my_pool = 0;
void* next_free_part = 0;
void* my_alloc (int block_size)
{
void* ptr = next_free_part;
next_free_part = ((char*)next_free_part) + block_size + RED_ZONE_SIZE;
VALGRIND_MALLOCLIKE_BLOCK (ptr, block_size, RED_ZONE_SIZE, 0);
return ptr;
}
void my_dealloc (void* block)
{
VALGRIND_FREELIKE_BLOCK (block, RED_ZONE_SIZE);
}
void* local_create_pool (int pool_size)
{
void* ptr = malloc (pool_size);
return ptr;
}
// Test functions
void this_function_works (void)
{
my_pool = (void*)VALGRIND_NON_SIMD_CALL1( local_create_pool, POOL_SIZE );
next_free_part = my_pool;
void* p = my_alloc (70);
char* cp = (char*) p;
for (int i = 0; i < 70; ++i)
cp[i] = (char) i;
cp[70] = 70;
my_dealloc (p);
my_alloc (64);
}
void this_function_crashes_valgrind (void)
{
my_pool = malloc (POOL_SIZE);
next_free_part = my_pool;
void* p = my_alloc (70);
char* cp = (char*) p;
for (int i = 0; i < 70; ++i)
cp[i] = (char) i;
cp[70] = 70;
my_dealloc (p);
my_alloc (64);
}
int main ()
{
#define CRASH_VALGRIND
#ifdef CRASH_VALGRIND
this_function_crashes_valgrind ();
#else // CRASH_VALGRIND
this_function_works ();
#endif // CRASH_VALGRIND
return 0;
}
------------------------------------------------------------------------------
==9969== Addrcheck, a fine-grained address checker for x86-linux.
==9969== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward et al.
==9969== Using valgrind-2.2.0, a program supervision framework for x86-linux.
==9969== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward et al.
==9969== For more details, rerun with: -v
==9969==
==9969==
==9969== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==9969== malloc/free: in use at exit: 32064 bytes in 2 blocks.
==9969== malloc/free: 3 allocs, 1 frees, 32134 bytes allocated.
==9969== For counts of detected errors, rerun with: -v
Addrcheck: mac_leakcheck.c:409 (vgMAC_do_detect_memory_leaks): Assertion
`lc_shadows[i]->data + lc_shadows[i]->size < lc_shadows[i+1]->data' failed.
==9969== at 0xB002A4A9: ??? (vg_mylibc.c:1133)
==9969== by 0xB002A4A8: assert_fail (vg_mylibc.c:1133)
==9969== by 0xB002A4C9: vgPlain_skin_assert_fail (vg_mylibc.c:1138)
==9969== by 0xB1259238: vgMAC_do_detect_memory_leaks (mac_leakcheck.c:517)
sched status:
Thread 1: status = Runnable, associated_mx = 0x0, associated_cv = 0x0
==9969== at 0x34140C24: _vgw(float, long double,...)(...)(long
double,...)(short) (vg_intercept.c:120)
==9969== by 0x34260F35: exit (in /lib/libc-2.3.2.so)
==9969== by 0x3424D554: __libc_start_main (in /lib/libc-2.3.2.so)
==9969== by 0x804831C: (within /home/kwedig/test/valgrind_test)
|