[ale] g++ and c++: freeing unallocated space with delete
Benjamin Scherrey
scherrey at proteus-tech.com
Wed Nov 6 12:42:09 EST 2002
Its is always safe to call delete on a pointer with a value of zero. If your unallocated string pointer
happened to have a zero value then nothing would have happened. Otherwise, deleting non-zero
values that don't exist on the heap is undefined (but never pleasent) behaviour.
regards,
Ben Scherrey
11/6/2002 10:32:30 AM, "John Wells" <jb at sourceillustrated.com> wrote:
>I have a program that manipulates various objects on the heap. I recently
>added a bug (unintentionally) in one of my modifications in which the
>program tries to free unallocated space. In other words, it calls delete
>on an string pointer that hasn't been pointed anywhere.
>
>The odd thing is, for a long time it worked just fine with no errors under
>gcc/g++ 2.96. Recently, I had to downgrade for other reasons to 2.95 and
>started getting seg faults, which led me to the culprit.
>
>Why did this work before? Do certain versions of gcc/g++ handle mistakes
>like this for you? And, if so, is there any way to turn this behavior
>off, so that no non-standard modifications are made? I'd like this code
>to be as standards compliant and possible, and if there are errors on my
>part, I'd like to know about them.
>
>Of course, it could be something else entirely. ;-)
---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be
sent to listmaster at ale dot org.
More information about the Ale
mailing list