public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@suse.de>
To: Craig Rodrigues <rodrigc@attbi.com>
Cc: gcc@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: Throwing exception in constructor causes segfault
Date: Sat, 23 Feb 2002 15:20:00 -0000	[thread overview]
Message-ID: <je4rk7yfea.fsf@sykes.suse.de> (raw)
In-Reply-To: <20020223165846.A4678@attbi.com> (Craig Rodrigues's message of "Sat, 23 Feb 2002 16:58:46 -0500")

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

  reply	other threads:[~2002-02-23 22:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-23 12:56 Craig Rodrigues
2002-02-23 13:20 ` Andreas Schwab
2002-02-23 14:23   ` Craig Rodrigues
2002-02-23 15:20     ` Andreas Schwab [this message]
2002-03-17  5:54       ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=je4rk7yfea.fsf@sykes.suse.de \
    --to=schwab@suse.de \
    --cc=gcc@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    --cc=rodrigc@attbi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).