This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Throwing exception in constructor causes segfault
Craig Rodrigues <rodrigc@attbi.com> writes:
|> On Sat, Feb 23, 2002 at 09:56:48PM +0100, Andreas Schwab wrote:
|> > The problem is that operator delete[]() is receiving a different address
|> > than returned by operator new[](). It looks like it is not adjusted for
|> > the cookie.
|>
|> I don't understand the gcc exception handling code, so
|> can you explain this in more detail? What is a cookie
|> in this case?
The cookie is just the number of elements of the array that is placed at
the beginning of the memory allocated with new[]. This has nothing to do
with exceptions. It is needed so that delete[] knows how often it has to
call the destructor.
|> Also, in my testcase, if you comment out the delete[] p; line,
|> the testcase will still segfault. Looks like delete[] is
|> called in the stack unwind code for some reason, if you
|> don't call it yourself.
Yes, the unwinder deallocates the array, since the exception occures when
the memory is already allocated.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE GmbH, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."