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: Segmentation fault inside a call to the 'new' operator


Marilyn Davis wrote:
> > 
> > When this has happened to me using gcc, it was because I was writing
> > outside the memory previously assigned to me by a previous call to
> > new.

Umberto writes:

> Thanks Marilyn, but I think that my post was not clear enough.

No, it was perfectly clear and Marilyn's explanation is the correct one.
If you ever see a crash inside new or malloc, the reason is always heap
corruption: the data structures used by malloc have been corrupted.
This can happen if you write to memory that you have not allocated
or have already freed, if you write beyond the end of memory you
have allocated, or if you free the same memory twice.

(I write "always" but of course it is possible that it is some other
bug, it's just that 9999 cases out of 10000 heap corruption is the
problem).

There are a variety of packages designed to catch just this sort of
problem.  Electric Fence is one of the better free ones.



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