Questions tagged [segmentation-fault]

Segmentation faults occur when accessing memory which does not belong to your process. Use this tag along with a tag indicating the language and a tag indicating the operating system. Segmentation faults are typically the result of a dereference operation with pointer variables (most often containing an invalid address) or a buffer overflow. The root cause for an invalid pointer value may be far from the location generating the segmentation fault.

Segmentation faults occur when accessing memory which does not belong to your process. They are common and typically the result of:

  • using a pointer to something that has been deallocated;
  • using an uninitialized hence bogus pointer;
  • using a pointer;
  • overflowing a buffer; or
  • attempting to write to read-only memory

The error does not arise when manipulating the pointer variable itself (copying or assigning the pointer variable), but when accessing the memory the variable points to (i.e. dereferencing the pointer variable). To generate the segmentation fault, will deliver 11 to the process which has made illegal memory access. The default action of having segmentation fault is , generating a coredump file with basic process information.

Since the point where the segmentation fault is triggered may be far from the location where the environment and actions that generate the conditions for the segmentation fault, finding the root cause can be difficult, especially in a complex, multi-threaded application.

Segmentation fault is descriptive phrase from Unix and Linux families of operating systems labeling a general class of behavior in which the operating system detects a memory access by a process outside of the process' assigned memory resulting in the operating system terminating the process.

This behavior requires hardware support for protected memory which may not be available in some microprocessors.

Additional information can be found on...

If the program crashed due to

  1. unauthorized memory access
  2. using out-of-bound memory location
  3. using of uninitialized memory

and it has received SIGSEGV and/or a coredump file is getting generated, mark your questions using this tag.

13352 questions
97
votes
4 answers

How can I catch SIGSEGV (segmentation fault) and get a stack trace under JNI on Android?

I'm moving a project to the new Android Native Development Kit (i.e. JNI) and I'd like to catch SIGSEGV, should it occur (possibly also SIGILL, SIGABRT, SIGFPE) in order to present a nice crash reporting dialog, instead of (or before) what currently…
87
votes
4 answers

Interpreting segfault messages

What is the correct interpretation of the following segfault messages? segfault at 10 ip 00007f9bebcca90d sp 00007fffb62705f0 error 4 in libQtWebKit.so.4.5.2[7f9beb83a000+f6f000] segfault at 10 ip 00007fa44d78890d sp 00007fff43f6b720 error 4 in…
knorv
  • 49,059
  • 74
  • 210
  • 294
80
votes
2 answers

Compile and run program without main() in C

I'm trying to compile and run following program without main() function in C. I have compiled my program using the following command. gcc -nostartfiles nomain.c And compiler gives warning /usr/bin/ld: warning: cannot find entry symbol _start;…
msc
  • 33,420
  • 29
  • 119
  • 214
75
votes
1 answer

Definitive List of Common Reasons for Segmentation Faults

NOTE: We have a lot of segfault questions, with largely the same answers, so I'm trying to collapse them into a canonical question like we have for undefined reference. Although we have a question covering what a segmentation fault is, it…
CodeMouse92
  • 6,840
  • 14
  • 73
  • 130
74
votes
19 answers

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

I'm trying to execute a Python script, but I am getting the following error: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV) I'm using python 3.5.2 on a Linux Mint 18.1 Serena OS Can someone tell me why this happens, and how…
Andre
  • 1,149
  • 2
  • 10
  • 18
74
votes
5 answers

segfault only when NOT using debugger

I have a multithreaded C program, which consistently generates a segmentation fault at a specific point in the program. When I run it with gdb, no fault is shown. Can you think of any reason why the fault might occur only when not using the…
Benubird
  • 18,551
  • 27
  • 90
  • 141
74
votes
11 answers

What is the simplest standard conform way to produce a Segfault in C?

I think the question says it all. An example covering most standards from C89 to C11 would be helpful. I though of this one, but I guess it is just undefined behaviour: #include int main( int argc, char* argv[] ) { const char *s =…
math
  • 8,514
  • 10
  • 53
  • 61
73
votes
3 answers

How do you read a segfault kernel log message

This can be a very simple question, I'm am attempting to debug an application which generates the following segfault error in the kern.log kernel: myapp[15514]: segfault at 794ef0 ip 080513b sp 794ef0 error 6 in myapp[8048000+24000] Here are my…
Sullenx
  • 731
  • 1
  • 6
  • 3
68
votes
12 answers

Why is this RMagick call generating a segmentation fault?

I've been banging my head against the wall for the better part of an hour trying to figure out what's going wrong here, and I'm sure (or rather hoping) it's something fairly obvious that I'm overlooking. I'm using Ruby 1.9.1, Sinatra 1.0, and…
Grant Heaslip
  • 967
  • 2
  • 10
  • 16
67
votes
5 answers

Crash or "segmentation fault" when data is copied/scanned/read to an uninitialized pointer

This question is meant to be used as reference for all frequently asked questions of the nature: Why do I get a mysterious crash or "segmentation fault" when I copy/scan data to the address where an uninitialised pointer points to? For…
Lundin
  • 195,001
  • 40
  • 254
  • 396
64
votes
4 answers

segmentation fault : 11

I'm having a problem with some program, I have searched about segmentation faults, by I don't understand them quite well, the only thing I know is that presumably I am trying to access some memory I shouldn't. The problem is that I see my code and…
Ariaramnes
  • 943
  • 2
  • 10
  • 18
61
votes
2 answers

"Unexplainable" core dump

I've seen many core dumps in my life, but this one has me stumped. Context: multi-threaded Linux/x86_64 program running on a cluster of AMD Barcelona CPUs the code that crashes is executed a lot running 1000 instances of the program (the exact same…
Employed Russian
  • 199,314
  • 34
  • 295
  • 362
56
votes
4 answers

Segmentation fault at glGenVertexArrays( 1, &vao );

My gdb backtrace gives: (gdb) backtrace #0 0x00000000 in ?? () #1 0x0804a211 in init () at example1.cpp:147 #2 0x0804a6bc in main (argc=1, argv=0xbffff3d4) at example1.cpp:283 Not very informative. Eclipse debugger at least lets me see that it…
Rooster
  • 1,267
  • 3
  • 15
  • 23
56
votes
8 answers

Line number of segmentation fault

Is there any gcc option I can set that will give me the line number of the segmentation fault? I know I can: Debug line by line Put printfs in the code to narrow down. Edits: bt / where on gdb give No stack. Helpful suggestion
Rohit
  • 1,710
  • 5
  • 20
  • 29
54
votes
6 answers

How to return a class object by reference in C++?

I have a class called Object which stores some data. I would like to return it by reference using a function like this: Object& return_Object(); Then, in my code, I would call it like this: Object myObject = return_Object(); I have written…
user788171
  • 16,753
  • 40
  • 98
  • 125