[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: delete causes crash with a character array
From: |
Ulrich Eckhardt |
Subject: |
Re: delete causes crash with a character array |
Date: |
Sun, 13 Feb 2005 13:19:10 +0100 |
User-agent: |
KNode/0.8.1 |
Alex Vinokur wrote:
> GNU g++ 3.3.3, Cygwin
[...]
> static char* mbuffer = NULL;
> void doit()
> {
> // Stuff
> mbuffer = new (nothrow) char [1001];
> assert (mbuffer != NULL);
>
> // Stuff
>
> assert (mbuffer != NULL);
> delete[] mbuffer; // Sometimes crashed here (not always).
> mbuffer = NULL;
>
> // Stuff
> }
>
> How can one detect what causes the crash?
The code you show is fine, though you should check for the returnvalue of
new (hint: assert() is not enough). Please reduce that to a minimal
example that reproduces the described behaviour and make a backtrace while
running in a debugger. Also, is this specific to g++ and/or Cygwin? I
guess the problem is in the code you don't show, something like smashing
the stack/heap or so.
Uli
--
http://gcc.gnu.org/faq.html
http://parashift.com/c++-faq-lite/