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
51
votes
3 answers

Segmentation fault when using a shared_ptr for private_key

Updates [X] I discovered this happen when TLS::credentials creds is declared on global scope but if I declare it outside seg fault won't happen. I need it to be global because it helps with caching certificates and that multiple threads can use…
jeffbRTC
  • 1,941
  • 10
  • 29
47
votes
9 answers

What can cause segmentation faults in C++?

I noticed there's not question with a list of common causes of segmentation faults in C++, so I thought I'd add it. Naturally it's community Wiki, since there's no one correct answer. I think this might be useful for newer programmers learning C++,…
fluffels
  • 4,051
  • 7
  • 35
  • 53
45
votes
22 answers

unable to execute command: Segmentation fault: 11 swift frontend command failed due to signal (use -v to see invocation)

I have an iOS swift program that compiles and runs fine on Xcode Beta2. When I downloaded beta4, I got a few syntax errors for the new swift language which I corrected. I now get this error: :0: error: unable to execute command:…
Salman Hasrat Khan
  • 1,971
  • 1
  • 20
  • 27
41
votes
7 answers

Bus error vs Segmentation fault

Difference between a bus error and a segmentation fault? Can it happen that a program gives a seg fault and stops for the first time and for the second time it may give a bus error and exit ?
Thunderboltz
  • 1,597
  • 3
  • 14
  • 16
39
votes
4 answers

What is the difference between a segmentation fault and a stack overflow?

For example when we call say, a recursive function, the successive calls are stored in the stack. However, due to an error if it goes on infinitely the error is 'Segmentation fault' (as seen on GCC). Shouldn't it have been 'stack-overflow'? What…
AruniRC
  • 5,070
  • 7
  • 43
  • 73
38
votes
4 answers

Returning this pointer from a function

I am trying to return a pointer from a function. But I am getting a segmentation fault. Someone please tell what is wrong with the code #include int *fun(); main() { int *ptr; ptr = fun(); printf("%d", *ptr); } int *fun() { …
user567879
  • 5,139
  • 20
  • 71
  • 105
38
votes
6 answers

strlen not checking for NULL

Why is strlen() not checking for NULL? if I do strlen(NULL), the program segmentation faults. Trying to understand the rationale behind it (if any).
hari
  • 9,439
  • 27
  • 76
  • 110
38
votes
2 answers

Segfault on declaring a variable of type vector>

Code Here is the program that gives the segfault. #include #include #include int main() { std::cout << "Hello World" << std::endl; std::vector> y {}; std::cout << "Hello World" <<…
Nawaz
  • 353,942
  • 115
  • 666
  • 851
38
votes
2 answers

Segfaults in malloc() and malloc_consolidate()

My application segfaults sometimes and mainly in malloc() and malloc_consolidate() when I look at the backtrace in gdb. I verified that the machine has enough memory available, it didn't even start swapping. I checked ulimits for data segement and…
Gene Vincent
  • 5,237
  • 9
  • 50
  • 86
37
votes
11 answers

Pycharm debugger instantly exits with 139 code

After upgrade from Pycharm 2017.2.3 to Pycharm 2017.1.4 Pycharm's Debugger suggested to build cpython (or sth associated with it): path/to/my/python /opt/pycharm-community-2017.1.4/helpers/pydev/setup_cython.py build_ext --inplace After I did this,…
dankal444
  • 3,172
  • 1
  • 23
  • 35
37
votes
2 answers

What is a segmentation fault on Linux?

In Linux: What is a segmentation fault? I know it crashes programs, but is that some sort of memory leak problem, or something completely unrelated? Also, how do you deal with these? Is this typically a problem with the computer set-up, or within…
Russel
  • 3,609
  • 8
  • 33
  • 32
36
votes
3 answers

segmentation fault vs page fault

I was wondering what differences and relations are between segmentation fault and page fault? Does segmentation fault only belong to segmented memory model? Does page fault only belong to paged memory model? If both are yes, since most computer…
Tim
  • 1
  • 141
  • 372
  • 590
36
votes
5 answers

caught segfault - 'memory not mapped' error in R

I have a problem running some R scripts on our cluster. The problems appeared suddenly (all the scripts were working just fine but one day they started giving a caught segfault error). I cannot provide reproducible code because I can't even…
Janina
  • 441
  • 1
  • 4
  • 13
34
votes
4 answers

Can a stack overflow result in something other than a segmentation fault?

In a compiled program (let's say C or C++, but I guess this question could extend to any non-VM-ish language with a call stack) - very often when you overflow your stack, you get a segmentation fault: Stack overflow is [a] cause, segmentation fault…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
33
votes
2 answers

Why does const int main = 195 result in a working program but without the const it ends in a segmentation fault?

Consider following C program (see live demo here). const int main = 195; I know that in the real world no programmer writes code like this, because it serves no useful purpose and doesn't make any sense. But when I remove the const keyword from…
Destructor
  • 14,123
  • 11
  • 61
  • 126