tags:

views:

129

answers:

2
+3  Q: 

malloc error C++

Possible Duplicate:
malloc.c:3074 error?

I am getting this strange error on execution of my C++ code:

malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
Aborted

The program runs fine upto a point where it catches the above Segmentation fault(SIGSEGV) from an already executed line. I found out this using gdb.

+6  A: 

Something has corrupted the heap by writing to an invalid memory location. The most likely causes are writing outside the bounds of an allocated object, or writing to an object after it has been deleted.

These errors can be difficult to track down with a debugger. The best tool is a memory checker, such as valgrind.

Mike Seymour
it was a silly mistake and valgrind pointed out where exactly the mistake was .. thanks
Akhil
+1  A: 

Based on your statement that the breaking line is called previously in program's execution and runs without fail to a point: This error is prabably caused by "damaged" memory structures.

This kind of strange and inconsistent behavior can be expected if you were to allocate memory and overrun writing to the buffer or if you were to allocate memory and then use the returned address without checking it to ensure that it is a non-zero address (memory allocation failure).

NTDLS