[Gc] behaviour of GC_local_malloc(0)

Peter Wang wangp at students.cs.mu.oz.au
Thu Apr 20 07:23:45 PDT 2006

On 2006-04-19, Hans Boehm <Hans.Boehm at hp.com> wrote:
> 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
> ignored.

Thanks, I've tried that now.  It did reduce the number of crashes in the
test cases of the Mercury compiler (what I'm working on), but some were
still present.  Maybe I did something wrong though.

(Actually, for our case, zero-size allocations seems to be an accident
rather than necessary by design, so just returning NULL was enough.)


More information about the Gc mailing list