Splint does a good job tracking down memory leaks in C code. Every malloc()
should have a matching free()
. But BoehmGC-collected code uses GC_MALLOC()
with no matching GC_FREE()
. This makes Splint go crazy with tons of messages about memory leaks that aren't actually there.
Does anyone know the proper annotation for such code so that Splint no longer shows spurious memory leak messages?
In particular, could someone annotate Wikipedia's BoehmGC example?
#include <assert.h>
#include <stdio.h>
#include <gc.h>
int main(void)
{
int i;
GC_INIT();
for (i = 0; i < 10000000; ++i)
{
int **p = GC_MALLOC(sizeof(int *));
int *q = GC_MALLOC_ATOMIC(sizeof(int));
assert(*p == 0);
*p = GC_REALLOC(q, 2 * sizeof(int));
if (i % 100000 == 0)
printf("Heap size = %zu\n", GC_get_heap_size());
}
return 0;
}