Re: RFC: introduce scoped cleanups

Joel Brobecker
2013-06-03T06:07:25Z

> My one concern about this code is that, if a stack cleanup should be
> leaked, then any future cleanup operation will refer to invalid memory.
>
> Right now, cleanup failures like this are a memory leak with the
> possibility of wrong behavior -- but the new way seems more directly
> fatal.
>
> Another option would be to allocate cleanups on an obstack.
> This would often be efficient and would avoid the above problem.

A very valid concern, IMO! I've never seen heap allocation as
a reason for concern with respect to performance, and thus have
never hesitated calling malloc. The only reason I have prefered
alloca whenever possible is that it allows me to be lazy :-)!

But this made me realize something: Why would someone want to do
stack-cleanups instead of just calling alloca directly? Since
alloca is basically a call-and-forget, what's the advantage of
going through a stack-based cleanup?

Regardless of the above, I like the idea of performing the cleanups
on an obstack; fast and yet a little more resilient to programming
errors. Not sure if that would be something easy to implement or not,
though.

--
Joel