Hi all I just write a small MemoryHook library with c++ and use as preload.But every time I start running, there is a big memory allocation,the size is 72704.I try to find all related library in ldd list, but no size is 72704. The usage is like this: LD_PRELOAD=./libPreload.so ./XXX
My initialize code: * static void TraceInitialize()* * {#ifdef _DEBUG fprintf( stderr, "call TraceInitialize\n" ); #endif pthread_mutex_lock( &s_mutexInit ); if ( s_status == TS_INITIALIZED ) { pthread_mutex_unlock( &s_mutexInit ); return; } s_status = TS_INITIALIZING; MemoryManager::initialize(); s_pRealMalloc = (FUNC_MALLOC)dlsym(RTLD_NEXT, "malloc"); s_pRealCalloc = (FUNC_CALLOC)dlsym(RTLD_NEXT, "calloc"); s_pRealRealloc = (FUNC_REALLOC)dlsym(RTLD_NEXT, "realloc"); s_pRealMemalign = (FUNC_MEMALIGN)dlsym(RTLD_NEXT, "memalign"); s_pRealValloc = (FUNC_VALLOC)dlsym(RTLD_NEXT, "valloc"); s_pRealFree = (FUNC_FREE)dlsym(RTLD_NEXT, "free"); assert( !( NULL == s_pRealMalloc || NULL == s_pRealCalloc || NULL == s_pRealRealloc || NULL == s_pRealMemalign || NULL == s_pRealValloc || NULL == s_pRealFree ) ); s_status = TS_INITIALIZED; // printMap(); pthread_mutex_unlock( &s_mutexInit ); }* and trace malloc call: * static int s_no_hook = 0;* * void* TraceMalloc( size_t size ) { if ( s_status == TS_INITIALIZING ) return mockMemory::_mockMalloc( size ); if ( s_status != TS_INITIALIZED ) TraceInitialize(); void* p = _impMalloc( size, __sync_fetch_and_add( &s_no_hook, 1 ) ); __sync_fetch_and_sub( &s_no_hook, 1 ); return p; }* And there is an additional problem that can't count the memory release of static global variables.I can't find a suitable time to do this,even with __attribute__ ((destructor(101))). How can I fix these two bugs? Complete code link: https://github.com/ddkv587/MemoryHook
_______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users