[Gc] GC as leak detecto

Juan Jose Garcia Ripoll lisp at arrakis.es
Fri Oct 7 05:29:41 PDT 2005


[Sorry for possible duplicates]

Hi,

  these days I have been using the garbage collector to investigate the
memory use and potential leaks in a C++ program. To get the most of the
information I have done the following:

1) Configure the GC with --disable-threads --disable-cplusplus
--enable-full-debug --enable-redirect-malloc

2) Define my own new/delete operators as indicated below.
   All routines in my program use the defined new/delete operators.

3) Somewhere in my program, these statements are executed:
        GC_find_leak = 1;
        GC_start_debugging();

Now, when I run the program I get lines like 

        Leaked atomic object at start: 0x8138e40, appr. length: 64
        Leaked atomic object at start: 0x8138ec0, appr. length: 64
        Leaked atomic object at start: 0x81350c0, appr. length: 64
        Leaked atomic object at start: 0x8135200, appr. length: 64

The problem is that there is no debug information in them. I have tried
to track down where these pointers come from or where they are generated
without much success. The system routines malloc/free seem to be
actually replaced by the debug ones from the garbage collector, and if I
set a watch point in any of the above pointers I typically end up in
GC_store_debug_info.

I am using the version 6.5 of the garbage collector in a Linux Ubuntu
5.04. Can it be that the garbage collector is getting confused and those
leaks do not exist? Or is my program probably smashing the debug region
of these pointers?

Running the same program in valgrind (without the GC of course) does not
seem to point any problems.

Regards

Juanjo

---------
inline void *operator new(size_t s, bool atomic, const char *f, int i) {
    if (atomic)
        return GC_debug_malloc_atomic(s, f, i);
    else
        return GC_debug_malloc(s, f, i);
}

inline void *operator new[](size_t s, bool atomic, const char *f, int i)
{
    return ::operator new(s, atomic, f, i);
}

void *operator new(size_t s)
{
    return GC_debug_malloc(s, __FILE__, __LINE__);
}

void operator delete(void *p)
{
    return GC_debug_free(p);
}
void *operator new[](size_t s)
{
    return GC_debug_malloc(s, __FILE__, __LINE__);
}

void operator delete[](void *p)
{
    return GC_debug_free(p);
}





More information about the Gc mailing list