7

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.

darwin
  • 71
  • 1
  • 1
  • 3
  • Getting application memory usage is a platform-specific thing. You'll need to provide some more details. I would suggest that you also file a new question, minus all the irrelevant stuff in this one. – Rook Sep 21 '18 at 06:50
  • 1
    If a program have no memory to allocate, it will raise `bad_alloc` exception. I think you should try to just handle the exception – Amir Rasulov Sep 21 '18 at 07:30
  • @AmirRasulov, Thank you very much Amir jan. I just do not understand why no `core` is created under `ubuntu` if this is an exception. – darwin Sep 21 '18 at 08:28
  • "I just do not understand why no core is created" - see [this question](https://stackoverflow.com/questions/42851670/how-to-generate-core-dump-on-addresssanitizer-error). – yugr Sep 21 '18 at 08:38
  • @yugr, thank you very much. I am wondering if I can set that environment variable from CMake. – darwin Sep 23 '18 at 23:24
  • @yugr, Is this the way? `set( ENV{ASAN_OPTIONS} 1 );set( ENV{abort_on_error} 1 );set( ENV{ASAN_OPTIONS} 0 ); set( ENV{...:disable_coredump} 0 ); set( ENV{...:unmap_shadow_on_exit} 1 ); ` – darwin Sep 23 '18 at 23:26
  • @darwin They are normally just set in shell before running tests via `export ASAN_OPTIONS=abort_on_error=1:disable_coredump=0` or by prepending to test cmdline via `ASAN_OPTIONS=... myprog arg1 arg2 ...` – yugr Sep 24 '18 at 08:49
  • @darwin you could add an answer to this question and accept it. – yugr Dec 28 '21 at 09:41

0 Answers0