Answer the question
In order to leave comments, you need to log in
What does this error mean in C++?
Unfortunately, I am not at all an expert on C ++, or on system programming. Therefore, I need the help of real experts.
I have a program that is written in C++ (there are sources) and compiled for 32-bit Ubuntu 14.04. Usually this program works fine, but on some combinations of incoming data, it quietly dies with a Segmentation fault . Since the application works as a multi-threaded server, I had no way to understand what and how it was dropping. And I, as a system administrator, could only solve this problem by restarting the daemon. But yesterday there was only one request that successfully failed this server. Its repeated call still successfully kills the application.
Armed with knowledge from Google, I added the line ulimit -c unlimited
to the script from /etc/init.d before starting and got a dump when it crashed. Then I fed it to the GDB input and got the following information:
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x080ac8a6 in size (this=<optimized out>, this=<optimized out>) at /usr/include/c++/4.8/bits/stl_vector.h:646
646 { return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
Answer the question
In order to leave comments, you need to log in
An error in the bowels of the STL is an unlikely event. This library has been tested for years on a huge number of projects. The fact that the error manifested itself in std:: vector does not mean at all that the error is there. Most likely - the code is trying to work with remote memory, calls the function for getting the size, and since the object does not exist, the program crashes.
This is completely normal for programs with manual memory management (well, it seems to happen for the rest too).
Why the error may occur from time to time: There are many reasons for this. Maybe incorrect work with multithreading (and here it already depends on the OS how it is and what it will distribute) leads to the fact that occasionally one thread accesses a resource remote by another thread. Maybe the memory error does not appear immediately because at least some values refer to non-existent memory, but physically this memory is in the address space of your program, which means that the OS thinks that everything is in order. Well, when the pointers go beyond this space, a big boom happens.
Since you have a query that is guaranteed to reproduce the problem, you should try to debug your server and find this error.
As a way to clarify the situation, you can try using valgrind, it also monitors leaks and intercepts access to "foreign" memory if you're lucky - this is one option, another option, if you have access to the source, recompile the program with the -fsanitize=address flag, with this flag, the program will spit out memory errors (which usually leads to a segmentation fault).
this=optimized out, this=optimized out
The most common mistake that causes a Segmentation fault is to free memory and then access it. You can try to set a static analyzer on the code, it will help you find errors in the code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question