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
14
votes
1 answer

Segmentation faults occur when I run a parallel program with Open MPI

on my previous post I needed to distribute data of pgm files among 10 computers. With help from Jonathan Dursi and Shawn Chin, I have integrate the code. I can compile my program but it got segmentation fault. I ran but nothing happen mpirun -np 10…
arep
  • 155
  • 1
  • 2
  • 7
14
votes
4 answers

Passing an array of strings as parameter to a function in C

I want a simple function that receives a string and returns an array of strings after some parsing. So, this is my function signature: int parse(const char *foo, char **sep_foo, int *sep_foo_qty) { int i; char *token; ... …
mmutilva
  • 18,688
  • 22
  • 59
  • 82
14
votes
5 answers

Turning on g++ optimization causes segfault - I don't get it

I've been working on my program, and I decided to turn on some optimizations using g++ -O3. Suddenly, my program started segfaulting. I've hunted the problematic code down, and minimized my program to something that still segfaults (only when using…
robrene
  • 359
  • 3
  • 14
14
votes
4 answers

segfault during __cxa_allocate_exception in SWIG wrapped library

While developing a SWIG wrapped C++ library for Ruby, we came across an unexplained crash during exception handling inside the C++ code. I'm not sure of the specific circumstances to recreate the issue, but it happened first during a call to…
lefticus
  • 3,346
  • 2
  • 24
  • 28
14
votes
1 answer

Segmentation Fault Catch

I have a python script and it will loop through bunch of maya files and do some stuff. But some time maya get seg fault and my script will stop there. I tried with signal and multiprocess. But both failed. import os, optparse, glob, json,…
Achayan
  • 5,720
  • 2
  • 39
  • 61
14
votes
4 answers

Swift Project Builds and runs but fails to Archive

I have a xcode project and running on the device, debug build everything is fine. However when i try to archive the project im getting a segfault from the Swift Compiler: 0 swift 0x0000000105c36608…
Jozef Dransfield
  • 524
  • 4
  • 11
14
votes
1 answer

Fortran 90 - "Segmentation fault - invalid memory reference" with scalable 3D array

I have compiled a fortran 90 program with gfortran which builds a scalable 3D array in a way I want. Upon running, I get the following error: Program received signal SIGSEGV: Segmentation fault - invalid memory reference. Backtrace for this…
Lorde555
  • 141
  • 1
  • 1
  • 4
14
votes
5 answers

Why is Ruby throwing a Segmentation fault on only my system, and only in this Rails application?

I'm not exactly sure how to properly debug this but have tried a few different approaches that have chewed up time, but not solved the problem. At least 4 other people in my office can execute this code on identical machines with the same version of…
Luke Bayes
  • 3,234
  • 2
  • 25
  • 20
13
votes
1 answer

Segmentation fault in malloc_consolidate (malloc.c) that valgrind doesn't detect

My program goes in segmentation faults, and I cannot find the cause. The worst part is, the function in question does not always lead to segfault. GDB confirms the bug and yields this backtrace: Program received signal SIGSEGV, Segmentation…
Jir
  • 2,985
  • 8
  • 44
  • 66
13
votes
2 answers

Java Segmentation fault when try to allocate buffer sizes larger than 256 MB

I am using a 64-bit JVM (Oracle), when i try to allocate buffer sizes larger than 256 MB it complains and throws a "segmentation fault" error. I and allocation direct memory buffers using java NIO, and transferring and receiving these objects to…
suleman
  • 147
  • 1
  • 1
  • 3
13
votes
3 answers

Passing std::filesystem::path to a function segfaults

When I attempt to use std::filesystem::path as a function argument, it segfaults on my machine. Here is a minimal example: #include void thing(const std::filesystem::path& p) { return; } int main() { thing("test"); return…
Astrognome
  • 303
  • 3
  • 9
13
votes
5 answers

What can cause a segmentation fault using delete command in C++?

I've written a program that allocates a new object of the class T like this: T* obj = new T(tid); where tid is an int Somewhere else in my code, I'm trying to release the object I've allocated, which is inside a vector, using: delete(myVec[i]); …
Zach
  • 537
  • 4
  • 9
  • 19
13
votes
1 answer

PySide segmentation fault on QObject instantiation

I have a class that is a base for my other non-qt classes. This class instantiates QObject class with Signal instance. Unfortunately, sometimes it raises Segmentation Fault error. Here is my code: class PublisherSignal(QObject): notify =…
Djent
  • 2,877
  • 10
  • 41
  • 66
13
votes
2 answers

Set stack size with setrlimit() and provoke a stack overflow/segfault

In the given example below I try to set the stacksize to 1kb. Why is it now possible to allocate an array of ints on the stack with size 8kb in foo() ? #include #include void foo(void); int main() { struct rlimit lim =…
tur1ng
  • 3,139
  • 5
  • 24
  • 31
13
votes
1 answer

Segmentation fault on gcc caused by lambda wrapper over variadic template function call

I've spent quite a few hours today trying to understand why this code segfaults on g++6.2 and g++7.0, while happily working as intended on clang++3.9 (and 4.0). I reduced the issue to a 85 lines self-contained code snippet, which does not segfault…
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416