Re: [gtk-list] Re: recursive gtk_main() calls and garbage collection



On 8 Nov 1997, Marius Vollmer wrote:

> Tim Janik <Tim.Janik@Hamburg.Netsurf.DE> writes:
> 
> > now gtk_main() is called recursively within the same function that did the
> > alloca(), and it invokes an idle handler that does an alloc(0) call (for
> > garbage collection). after the recursive call our function accesses
> > the alloca()ed memory and - boom corruption...
> 
> Are you sure that it works that way?  I would expect alloca(0) to be
> careful not to free memory that has been allocated in a frame below
> the current one.
> 
> If it doesn't, wouldn't that be a bug in the library implementation of
> alloca?
> 
> I'm only guessing here...

GNU alloca, in order to be (relatively) portable, doesn't really use the
stack, but instead uses a bit of magic to automatically free blocks of
memory that were allocated in a lower stack level. It doesn't do this
deallocation until the next time it is invoked, so I _presume_ that
alloca(0) is a hint to the GNU function to free such memory without
allocating anything new.

On a system with genuine stack-based alloca(), I wouldn't be completely
surprised if it crashed (much as malloc(0) can potentially crash in broken
or memory-debugging implementations).

I'm not sure why anyone would want to invoke alloca(0) in an idle handler,
as the memory should be freed on the next real alloca() in any case. 

-- 
Kenneth Albanowski (kjahds@kjahds.com, CIS: 70705,126)




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]