ERROR: AddressSanitizer failed to allocate

Viewed 8816

I have written a program for a research calculation and this program crashed after a long time at a around a certain location. Unfortunately, the program is too big to create a MWE out of it. But, I realized when crashing, no core file is created and no message is shown. In addition, when I created some std::cout commands to show messages (I am on Linux without debugger), then I found the location of crash. When I create more number of screen output logs the location of crash changes while they only affect the screen not the variables. To me, this is an indicator for stack corruption.

I searched and I found these options which I added to my gcc compiler

-fsanitize=address -fno-omit-frame-pointer

Here is the end of the output result:

==2603==ERROR: AddressSanitizer failed to allocate 0x10000 (65536) bytes of memory at address 0x62e60b3f0 (error code: 12)
ERROR: Failed to mmap

It happens right before

my_vector2.push_back(my_vector1[i]);

To detect if this is because of my_vector1 and my_vector2, I have broken the code to

auto AAA=my_vector1[i];
cout<<"AAA"<<endl;
my_vector2.push_back(AAA);
cout<<"BBB"<<endl; /* does not reach here */

Then, I checked it again:

AAA
==2603==ERROR: AddressSanitizer failed to allocate 0x10000 (65536) bytes of memory at address 0x62e60b3f0 (error code: 12)
ERROR: Failed to mmap

which means BBB output does not reach.

Although, there are some results about this error on the Internet, what make my case different is that

1- The length of the allocation for me is 65536 according to the error message. This number is 2^16 which I am sure is not accidental and it has some meaning.

2- This happens for push_back function. I doubt STL has any bug.

The problem stops working either if I sanitize the address or not.

Is there any other clue to find the root of the bug?


Update

I have finally found the problem. 16GB RAM had made me arrogant. The system goes out of RAM. Here is the Sceenshot of the system manager a minute before the crash.

Now, my question is how to make the program detect such situations and create a proper error message in such cases.

0 Answers
Related