This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Question


> 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.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]