[Gc] Internal memory leak for small objects

Ivan Maidanski ivmai at mail.ru
Fri Nov 28 06:27:13 PST 2008


Hi!

Consider this test app:

#include <stdio.h>
#include "gc.h"

void *ptr = 0;
int main(void)
{
  int j;
  GC_INIT();
  for (j = 60; j < 90; ++j) {
    void **p = GC_MALLOC(j*sizeof(void*));
    printf("%p\n",p);
    *p = ptr;
    ptr = p;
    GC_gcollect();
  }
  return 0;
}

The GC lib is built in config -DFIND_LEAK -DALL_INTERIOR_POINTERS (for simplicity). The test is compiled without any options. Here I use VC++ but the bug is platform-independent.

Running this test gives:
00180E88
00180D90
00181F00
00181E00
00182E40
00182D10
00182BE0
00182AB0
00182980
00182850
00182720
001825F0
001824C0
00182390
00182260
00182130
00183E60
00183CF0
00183B80
00183A10
001838A0
00183730
001835C0
00183450
001832E0
00183170
00184E60
00183000
00184CF0
00184B80

Log file contains:
Leaked composite object at start: 00182000, appr. length: 304
Leaked composite object at start: 00182000, appr. length: 304
Leaked composite object at start: 00182000, appr. length: 304
Leaked composite object at start: 00182000, appr. length: 304
Leaked composite object at start: 00182000, appr. length: 304
Leaked composite object at start: 00183000, appr. length: 368
Leaked composite object at start: 00182000, appr. length: 304
Leaked composite object at start: 00182000, appr. length: 304

You can see that leaked object is:
1. SMALL_OBJ;
2. never returned by GC_malloc.

I don't know whether the bug is specific to FIND_LEAK mode or not.
In fact, this object is removed from GC_obj_kinds list by GC_start_reclaim(FALSE) instead of being reconstructed. I'm failed to find out more...

Bye.



More information about the Gc mailing list