This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Question
- To: TAtanassov at printrak dot com ("Tervel Atanassov (Anaheim)")
- Subject: Re: Question
- From: Joe Buck <jbuck at synopsys dot COM>
- Date: Mon, 9 Jul 2001 20:20:15 -0700 (PDT)
- Cc: gcc at gcc dot gnu dot org ('gcc at gcc dot gnu dot org')
> Hello,
>
> I am trying to port some more code from windows 2000 to linux. The specific
> functionality I would like to port is called "Structured Exception Handling"
> and it works like so:
This technique seems unsafe to me, whether on Windows or Linux or anywhere
else. The reason is that a signal can occur at any time, including
halfway through a constructor when an object is in an inconsistent state.
Consider the following very simple code:
char* foo = 0;
try {
foo = new char[100];
...
}
catch (StructuredException) {
...
}
Now suppose you turn a SIGINT (user types control-C) into a "structured
exception"). Should the catch block do "delete foo;" or not? Even if
it does, there's a window between the allocation of the memory and the
assignment to foo, so at the least there's going to be a memory leak.
At worst, you'll have to change all of your code to block signals during
critical regions, regions that weren't critical before.
- References:
- Question
- From: Tervel Atanassov (Anaheim)