This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: memory allocation problem
- To: js1 at microwave dot ph dot msstate dot edu (Jiann-Ming Su)
- Subject: Re: memory allocation problem
- From: Joe Buck <jbuck at racerx dot synopsys dot com>
- Date: Mon, 20 Nov 2000 17:17:28 -0800 (PST)
- Cc: gcc at gcc dot gnu dot org
> 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.