Platinum Rift 2 - *** Error in `/tmp/Answer': malloc(): memory corruption

I’m writing the bot in C++ and almost always gets an error similar to the following:

Standard Error Stream:
*** Error in /tmp/Answer': malloc(): memory corruption: 0x0000000000613d90 *** Aborted. at raise.c. function __GI_raise (sig=sig@entry=6) on line 56 at abort.c. function __GI_abort () on line 89 at libc_fatal.c. function __libc_message (do_abort=do_abort@entry=1, fmt=fmt@entry=0x7ffff6b1bc60 "*** Error in%s’: %s: 0x%s ***\n") on line 175
at malloc.c.
function malloc_printerr (action=1, str=0x7ffff6b17d9f “malloc():
memory corruption”, ptr=) on line 4996
at malloc.c. function _int_malloc (av=0x7ffff6d59620 <main_arena>, bytes=8) on line 3447
at malloc.c. function __GI___libc_malloc (bytes=8) on line 2891
at new_allocator.h. function __gnu_cxx::new_allocator::allocate ( this=0x7fffffffe8a0, __n=2) on line 104
at alloc_traits.h. function std::allocator_traits<std::allocator >::allocate (__a=…, __n=2) on line 357
at stl_vector.h. function std::_Vector_base<int, std::allocator >::_M_allocate (this=0x7fffffffe8a0, __n=2) on line 170

It may happen on games with number of zones as low as 20. My program typically crashes at the end of the game.

I’m not manually managing memory. I’m using vector. Why is this happening?

You don’t use new, but vectors does. This error is the typical error when you are out of memory. You create too many things and never destroy them.

1 Like

Thanks for your reply. I don’t think I’m creating too many things on memory using vector. Items I’m creating shouldn’t exceed 768 MB which is the maximum memory that would be given to a C++ program.

How can I debug this thing? I’ve put a cerr to show the size of a suspicious growing vector. It even never exceeds 100 before this error occurs.

You can debug it by placing a cerr << "something" << endl; anytime you declare a new vector.

That’s (cerr) not enough.

However, I have found the problem. I was using a sorting algorithm to sort a set of data. The algorithm isn’t transitive. The details was discussed here.