Harald said:
Harald van D?k said:
01:29 +0100, Harald van D?k
On Wed, 05 Mar 2008 01:26:18 +0530, santosh wrote:
<snip>
Do you mean to say that memory allocated with alloca will be
properly freed even if the execution jumps to another function
via longjmp?
If he is, he's correct for at least the system I'm using, which
explains this its documentation for alloca.
Of course, as alloca is non-standard, other systems are permitted
to implement it differently. I don't know if any do, but I expect
it would be implemented the same way as VLAs, and VLAs can be
leaked by longjmp.
Huh? What makes you think that?
The fact that it's specifically listed in an example attached to the
description of longjmp.
7.13.2.1p5:
EXAMPLE The longjmp function that returns control back to the point
of the setjmp invocation might cause memory associated with a
variable length array object to be squandered.
[snip]
I think the "Huh?" referred not to the fact that VLAs can be leaked
by longjmp, but by the suggestion that alloca can be implemented the
same way as VLAs.
Oh, that's not how I read it, but it's certainly possible he meant
that. Thanks for pointing it out.
That's /not/ what David Thompson meant. To quote him:
Huh? What makes you think that? VLAs have the same lifetime as any
auto variable, which ends at any exit from the block (execution).
Any implementation that doesn't deallocate them is buggy. (Albeit not
nonconforming; nothing requires that auto space must be reused,
although that's the obvious purpose and universal choice.)
Of course, most implementations use a single stack for all
instance-related data (as M. Navia never tires of reminding us) and
allocating VLA space on that stack means it is implicitly freed when
the stack is cut back by the longjmp, so this is easy to get right.
<<<<<<
So he was talking about the possibility of memory for VLAs being leaked
with a longjmp call.
<snip>