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

How do I debug a segmentation fault in Mono on Ubuntu without any debugger?

I have an application that I recently split to run in separate processes that communicate with each other via local sockets. I split it out in hopes of increasing stability, as the core "watcher" process can detect a failure and restart the…
Louis Ingenthron
  • 1,267
  • 8
  • 21
3
votes
2 answers

Accessing pointers within a struct

At the moment I have the following code: typedef struct _hexagon { int *vertice[6]; int *path[6]; int resourceType; } hexagon; typedef struct _game { hexagon hexagons[5][5]; } Game; and in the main I have: Game g; // This is the…
Lobe
  • 528
  • 10
  • 25
3
votes
3 answers

Segmentation Fault when trying to use scanf on a struct

I'm pretty new to c and I'm pretty frustrated at the moment as well. Here's the code I have: typedef struct { char* fName; char* lName; char* pNum; char* address; char* email; } contactInfo; void addContact(){ contactInfo *contact; contact =…
Novacane
  • 119
  • 3
  • 14
3
votes
1 answer

python 2.7: Getting Segmentation fault when setting Menu in GUI programming with Tkinter

I'm getting a segmentation fault everytime i want to run this code : from Tkinter import * def gui(): root=Tk() menubar=Menu(root) filemenu=Menu(menubar,tearoff=0) filemenu.add_command(label='New',command=gui) …
Malik Fassi
  • 488
  • 1
  • 10
  • 25
3
votes
6 answers

Debugging a clobbered static variable in C (gdb broken?)

I've done a lot of programming but not much in C, and I need advice on debugging. I have a static variable (file scope) that is being clobbered after about 10-100 seconds of execution of a multithreaded program (using pthreads on OS X 10.4). My…
Aaron B
3
votes
1 answer

Valgrind leak detection with segfault

I'm checking my code for memory leaks. Everything is okay until I got the code: mSystem = new LightSystem(); sf::View *view = th::DisplayManager::Get()->GetCamera(); mSystem->SetView(*view); SetView does really tiny job (extracts a few members of…
Max Frai
  • 61,946
  • 78
  • 197
  • 306
2
votes
1 answer

Segmentation fault happened while calling a correct function

I am solving a 0-1knapsack problem. I solved the problem by brute force algorithm. In main.cpp int main(int argc, char *argv[]) { ...... int solution; solution = bruteForce(); ...... } The strange thing is, when I…
Po-Jen Lai
  • 411
  • 1
  • 8
  • 18
2
votes
1 answer

Need help debugging further into a SEGV issue - Android NDK

I am building a library with a large body of source code for Android. The library works fine if compiled for Linux x86. I am building it with the stand alone tool chain. I have had success with this previously with other libraries, so I feel like…
corbin
  • 1,446
  • 2
  • 27
  • 40
2
votes
4 answers

segfault after return 0;

I wrote a program to test my binary tree and when I run it, the program seems to crash (btree.exe has stopped working, Windows is checking for a solution ...). When I ran it through my debugger and placed the breakpoint on the function I suspect is…
Steve
  • 11,831
  • 14
  • 51
  • 63
2
votes
2 answers

File Segmentation when trying to write in a file

I am trying in C language to use the method of bisection to find the roots of some equation, however when I try to write every step of this process in a file I get the problem "Segmentation fault". This might be an idiot fault that I did, however I…
user1286390
  • 101
  • 1
  • 2
  • 6
2
votes
1 answer

python, skype4py

$ sudo python2.6 >>> import Skype4Py >>> skype = Skype4Py.Skype() >>> skype.Attach() And nothing happens.. just it turn me out to the console. And I'm trying next to get result without sudo $ python2.6 Python 2.6.6 (r266:84292, Mar 25 2011,…
2
votes
1 answer

Segmentation fault relating to the main statement - Using C++, SDL

Im using C++ and SDL to program a game, and even though I get no errors whenever I try to run it - I get a segmentation fault. I ran the gdb debugger and this is what it gave me when I used the backtrack function : "#0 main () at main.cpp:10" ,…
Trista N
  • 403
  • 1
  • 4
  • 11
2
votes
2 answers

Strange behaviour in Qt program when playing with destructors

I've started learning qt recently and was playing with it, also remembering a bit of c++ since I haven't used it in a while... Anyway, I made this simple test class to see what would happen when you have a dangling pointer: #include…
Nini Michaels
  • 341
  • 7
  • 17
2
votes
1 answer

segmentation fault due to freeing memory

I have been struggling to solve this problem but to no avail. In the code below, I use a char pointer (all_seq), but when I free it, at the end of the code, sometimes it segfaults. I say sometimes, because it apparently depends on the input file.…
user1274826
  • 21
  • 1
  • 2
2
votes
1 answer

Seg Fault happening because variable is getting changed

Basically I have some code that keeps seg faulting. The reason is because the current size of my data structure is getting changed and I don't know how. In the newMap function I set the size of the map to 0 then once I've set the values of the…
bpoc
  • 45
  • 5