[cfe-dev] [Bug] Wrong Exception Handling : Destructor not called immediately

suyog sarda sardask01 at gmail.com
Thu Apr 24 06:27:41 PDT 2014


>
> Your proposed change causes the destructor for the auto object to be run
> if the initializer throws, even if the auto var constructor hasn't been run
> yet.
>
>
My bad, i got carried away with specifics to the problem and didn't look at
whole picture.

Ok, right now, cleanup code of temporaries is getting emitted before entry
of auto variable gets added in the EHStack which is causing resource leak.
This is because, scope of the temporaries gets over (which causes their
cleanup code to emit) after initialization but before adding EHStack entry
of auto variable.
If the temporary storage duration is extended till full expression, then it
will be easy to use EHStack.

For auto variable emission there are three steps involved (Correct me if i
am wrong) :

1. EmitAlloca - emit code for alloca which will allocate memory
2. EmitInit - emit code for initializing the object which involves
evaluating the subexpression
3. EmitCleanup - EmitCleanup code for constructed object

The problem is after allocating memory successfully in 1st step, if
something goes wrong in initializing (exception in temporary destructor),
the memory allocated in 1st step is not cleaned because it happens in 3rd
step which is never visited.

Is their any other way to resolve this issue? Or only extending storage
duration will help in easy implementation?

-- 
With regards,
Suyog Sarda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140424/08b34280/attachment.html>


More information about the cfe-dev mailing list