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

Debugging Segmentation Faults on a Mac?

I'm having some problems with a program causing a segmentation fault when run on a Mac. I'm putting together an entry for the IOCCC, which means the following things are true about my program: It's a very small C program in a single file called…
electrodruid
  • 1,083
  • 2
  • 9
  • 13
11
votes
2 answers

Objective-C - ARC - NSNumber - Segmentation Fault

I have an objective-C program and I am using ARC (Automatic Reference Counting), it throws a segmentation fault in line 23 (see program below). Question 1) Why does the segmentation fault occur ? Given below is the…
11
votes
5 answers

Why does std::sort throw a segmentation fault on this code?

Can someone explain why the sort below causes seg faults? Is this a known bug with g++ (sorting vector of pointers)? I am compiling with g++ 4.5.2. #include #include #include using namespace std; typedef vector
Jack Cheng
  • 409
  • 3
  • 10
11
votes
9 answers

Try/Catch a segmentation fault on Linux

I have a Linux C++ application and I'd like to test an object pointer for validity before dereferencing it. However try/catch doesn't work for this on Linux because of the segmentation fault. How can this be done?
jackhab
  • 17,128
  • 37
  • 99
  • 136
11
votes
2 answers

Python PyGILState_{Ensure/Release} causes segfault while returning to C++ from Python code

UPDATE Well, it looks like adding PyEval_InitThreads() before the call to PyGILState_Ensure() does the trick. In my haste to figure things out I incorrectly attributed my "hanging" to PyEval_InitThreads(). However, after reading some Python…
Mr. Shickadance
  • 5,283
  • 9
  • 45
  • 61
11
votes
2 answers

Declaration of variable causes segmentation fault

I don't understand the reason for a segmentation fault error in my program. The code is available here At line 29 I declare a PclImage variable, defined with typedef like an array of struct. The definition of PclImage type is the following (from…
Muffo
  • 1,733
  • 2
  • 19
  • 29
11
votes
3 answers

Whats SIGSEGV, Segmentation fault in Qt

I have a Qt program which displays the data it receives over UDP. It works fine for around 30 seconds but after a while it gives Segmentation Fault and crashes. This 30 seconds is also not fixed. I used the debugger and got this: Program received…
user269037
  • 550
  • 2
  • 7
  • 15
11
votes
7 answers

Segmentation fault after free(), what are the common causes for this?

I get a segmentation fault after freeing a certain pointer: free(studentDB->name); I can get its value without any errors or warnings: printf("[DBG] studentDB->name: %s\n", studentDB->name); However, as I said, the program crashes when I try to…
Pieter
  • 31,619
  • 76
  • 167
  • 242
11
votes
4 answers

Java VM: reproducible SIGSEGV on both 1.6.0_17 and 1.6.0_18, how to report?

EDIT: This reproducible SIGSEGV happens on a Linux machine with more than one proc and more than 2GB of mem, so Java is defaulting to the -server mode. Interestingly enough if I force "-client" there's no crash anymore... (I'm still not too sure…
SyntaxT3rr0r
  • 27,745
  • 21
  • 87
  • 120
11
votes
3 answers

segfault in R using reshape2 package and dcast

RStudio was crashing when I tried to reshape a particular data frame using dcast (from the reshape2 package). I discovered that the crash was actually happening in R itself, so I ran my casting code in R.app and got the type of error that gives this…
eipi10
  • 91,525
  • 24
  • 209
  • 285
11
votes
2 answers

Python - C embedded Segmentation fault

I am facing a problem similar to the Py_initialize / Py_Finalize not working twice with numpy .. The basic coding in C: Py_Initialize(); import_array(); //Call a python function which imports numpy as a module //Py_Finalize() The program is in a…
vijayvammi
  • 218
  • 3
  • 12
11
votes
3 answers

How to diagnose these PHP-Code-Coverage segmentation and zend_mm_heap corrupted errors

I have been happily coding away on my Ubuntu machine. It's a beefy machine with plenty of RAM. I was working on 4 new classes, writing and running unit tests as I go. At some point I noticed that, while the unit tests were completing fine, code…
DatsunBing
  • 8,684
  • 17
  • 87
  • 172
11
votes
2 answers

What are segfault rip/rsp numbers and how to use them

When my linux application crashes, it produces a line in the logs something like: segfault at 0000000 rip 00003f32a823 rsp 000123ade323 error 4 What are those rip and rsp addresses? How do I use them to pinpoint the problem? Do they correspond to…
johnnys
11
votes
4 answers

Why doesn't my program seg fault when I dereference a NULL pointer inside of malloc?

I use this malloc style all the time int *rc = 0; rc = malloc(sizeof(*rc)); However, it doesn't seg fault even though when I call sizeof(*rc) I assume that rc==0, and I am dereferencing a NULL pointer.
CallMeNorm
  • 2,299
  • 1
  • 16
  • 23
11
votes
2 answers

Is this PyQt 4 python bug or wrongly behaving code?

Following code should create the QGraphicsView widget which owns one QGraphicsScene having text inside of it: #!/usr/bin/python import sys from PyQt4.QtGui import * if __name__ == '__main__': app = QApplication(sys.argv) view =…
jhnsn
  • 113
  • 1
  • 4