program received signal SIGSEGV, segmentation fault - c++

I am running a program in multi threaded environment it fails at some point. when i tried it with gdb than it is shoing the following error.
program received signal SIGSEGV, segmentation fault.
[switching to thread 0x7fff677b700 (LWP 2777)] 0x00007ffff7aa42b9 in
process_incomplete_rows (resultset=0x507950) at c/mgmt.c:479 479
c/mgmt.c: No such file or directory.
mgmt.c file is there and this code is working fine for some options but 2 or three options its giving this error. What could be the cause of this error. Its error in comiplation or in coe? or its error while accessing some data?

A segmentation fault is a runtime error that is usually due to referencing an invalid pointer. Usually that invalid pointer has never been initialized, but sometimes it is reusing an old pointer or writing past the end of an allocated memory chunk (such as past the end of a string).

It probably means that your node variable is either NULL or corrupted. Run your program in the debugger, stepping through it from some point prior to the crash up until it and see where you've messed it up. Or use one of the automated tools like Purify or Insure++ to track it down for you.

Related

Terminate the execution of a program after an error without the backtrace

I have several Fortran codes to run and sometimes I get an exception (segmentation fault for example):
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
This is not a big deal because a correction is possible. However, it stops the flow of the other execution with:
Backtrace for this error:
waiting at this time. With automatic testing, I do not care at this point about the backtrace and just want to display an error and I will come back to it later.
How can I prevent the program printing the backtrace for the error so that it just returns a value like 42?
I use gfortran 4.9.2.

How to track a invalid pointer in C++?

I have my code ready to run with PROOF.
Whenever I run code standalone I works fine, when I activate PROOF, my code crash with a Segmentation Fault.
With GDB I'm able to know exactly where it crashes: when I try to follow a pointer to a object. This makes me think that this pointer (that I'm absolutely sure it was valid before) is invalid and I have no idea why so.
Are there other options? can I track that pointer so I know where it was released?
Use valgrind memcheck tool with --leak-check=summary --track-origins=yes.
This shows invalid memory access (Segmentation Fault) and where they had been freed.

Weird segfault with std::malloc

I'm getting a segfault with the following line of code:
char* addr = (char*)std::malloc(bytes);
When running GDB I see that bytes has a value of 851984. As far as I know that shouldn't be a big deal. I can't seen anything wrong with it for the life of me. Anybody have some suggestions?
The actual segfault error is:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff674dd75 in malloc_consolidate (av=0x7ffff6a87720) at malloc.c:4254
There is (most likely) an issue somewhere earlier in your code which is corrupting heap structures, causing malloc to fail on allocation. You should try using a memory error detection tool like valgrind to debug this issue.

Possible reasons for segmentation fault on function exit

What possible reasons can you think of for a segmentation fault on exiting a function in C++? What I mean by that is, that I have a reproducible segmentation fault in a C++ program, and when I investigate using GDB is says
Program received signal SIGSEGV, Segmentation fault.
FooBar (bla=...) at foo.cpp:59
59 }
where the indicated line contains the closing bracket of my function.
There could be many reasons of this. Run program under Valgrind and most likely it will tell you exact reason or at least will help to investigate and narrow down the problem.
It's quite likely a buffer overrun on some buffer located on your stack. This overwrites the return address, so when your code tries to return to the previous stack frame, it instead jumps to some random address which is more likely than not non-executable, so you get a segmentation fault.
But without seeing some more code or more information about the crash, it's impossible to say what the exact cause is.
My first guess is the destructor of a class is freeing an invalid pointer.
in my case I had an std::thread that had not been properly joined.

gdb detected a segmentation fault. How to pinpoint the exact source?

(gdb) s
Things:action (this=0x7fffffffdce0, packet=0x62c980) at file:41
41 if( thing->work(data) ) {
(gdb) s
Program received signal SIGSEGV, Segmentation fault.
0x00000000004040e1 in Things:action (this=0x7fffffffdce0, packet=0x62c980) at file:41
41 if( thing->work(data) ) {
In a backtrace, call to work(data) is a last one; and the segmentation happened (as it seems) before the GDB-managed process entered work(data). In a list, there is no declaration of work(data), so guessing that more code was executed, than is shown by backtrace and latest step.
Can that segfault come from the bad pointer being passed as a function argument in a bad manner (without "extern C", or some other preparations)? (assuming no function code was executed)
How to get a detailed trace to determine, was any work() code executed after entering the function, or the error happened right at the moment, when process tried to enter the function, thereby passing it's arguments to libc?
As I said in the comment : I believe that the execution never reached work(data) because the this pointer is invalid (0x7fffffffdce0 looks like garbage). The SIGSEGV is on this->.
Has the object been destroyed / deleted at some point, and have you kept a reference or pointer to it ?
Well, work() can't have been started unless it's inline, or you it would have been on the top of the backtrace...
I would try disassembling to see what instruction triggered the SIGSEGV and go from there.