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: memory allocation problem



> I'm using egcs-2.91.66 with glibc-2.1.2.  In my c++ code, I call
> new to allocate 60 bytes of memory.  It returns a pointer to 0x806b5f0.
> Before freeing that buffer, I ask for 62 more bytes.  I get a pointer
> to 0x806b630.  It's pretty clear that 630(hex) minus 5f0 equals 40.
> 
> It's pretty clear what happens next.  I delete 0x806b5f0.  The program
> then seg faults when it tries to delete 0x806b630.  I'm running Linux
> 2.2.16 on Intel platform.  Anybody else experiencing this type of 
> problem?  Thanks for any help.

Almost certainly the problem is that you have corrupted the heap
(the heap is the region of memory managed by new/delete or malloc/free).
This will happen if you write to memory that has already been freed,
write beyond the end of an allocated segment, free the same memory
twice or call delete on an object that is not on the heap (was not
allocated by new).  Effects of heap corruption can show up much later
than the error that actually caused the problem.

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