Re: Garbage collection, part two...

From: Paul Anderson <paul_at_grammatech.com>
Date: Thu, 06 Apr 2000 21:04:05 -0400

Shiro:

> > I can think of plenty of nonsensical cases, such as:
> >
> > STk_makestring(CHARS(STk_makestring("one")));
> >
> > which doesn't make too much sense.
>
> STk_makestring creates its own copy, so shouldn't it be OK?

No! The result of STk_makestring("one") (call this s1) is
unused after it is passed to CHARS(). If it were allocated
to a register, then that register could be reused before the
second call to STk_makestring(), and s1 would then be a
candidate for collection. The implementation of STk_makestring
does a NEWCELL before it copies the string, so if that triggers
a garbage collection, then CHARS(s1) would be freed.

There are several things that might damage the string now that
it is freed. Some malloc implementations maintain a free list
by using the memory pointed to by the freed pointers. This could
overwrite the string. Also, other mallocs could take place such
as signal handler for SIGHADGC.

Frankly, I doubt if there are many places where this will be
a problem, but if anyone can think of other candidates I would
love to know about them.

Best regards,

Paul.
 
______
Paul Anderson. GrammaTech, Inc. Tel: +1 607 273-7340
mailto:paul_at_grammatech.com http://www.grammatech.com
Received on Fri Apr 07 2000 - 03:05:26 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST