[Gc] behaviour of GC_local_malloc(0)

Hans Boehm Hans.Boehm at hp.com
Wed Apr 19 22:54:36 PDT 2006

You're right.  This is a bug.  A size zero GC_local_malloc allocation
currently just returns a fixed address outside the real heap.  The only
pleasant property this has is that it can be implemented without an
explicit zero check in the allocator.

The trivial (untested) workaround consists of enabling the hdr == 0 test
in GC_free unconditionally, not just for malloc redirection.  That way
explicit deallocations of objects outside the real heap will be implicitly

I'm not sure whether that is the best real fix.


On Thu, 20 Apr 2006, Peter Wang wrote:

> Hello,
> The following program crashes at the GC_free() line.  I wonder if this
> is a bug in gc6.7, or if allocating zero bytes is not allowed.
> The crash does not occur with non-thread local allocation, nor with
> gc7.0alpha5, though.
>     #include <stdio.h>
>     #include "gc.h"
>     #include "gc_local_alloc.h"
>     int main(void)
>     {
> 	void *p;
> 	GC_init();
> 	p = GC_local_malloc(0);
> 	printf("%p\n", p);
> 	GC_free(p);
> 	return 0;
>     }
> I am testing on a x86-64, linux 2.6 machine.
> Peter
> _______________________________________________
> Gc mailing list
> Gc at linux.hpl.hp.com
> https://www.hpl.hp.com/hosted/linux/mail-archives/gc/

More information about the Gc mailing list