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

A segmentation fault error with 2D array

There is a weird segmentation fault error. The following code runs fine #include #include main() { int matrixSize = 1000; int i,j; double a[matrixSize][matrixSize]; for (i = 0; i < matrixSize; i++) …
Maxim Mayers
  • 185
  • 2
  • 6
2
votes
2 answers

How to recover from Segmentation fault in Python?

I am running the Python program to call the other 3rd module, which may written in C. In this case, how can I recover from the Segmentation fault and continue to process others in a loop? Segmentation Fault is not exception so that cannot be…
northtree
  • 8,569
  • 11
  • 61
  • 80
2
votes
1 answer

gethostbyname() (actually, Boost Asio resolve()) segfaults EXACTLY after 2 hours (120 mins, 7200 seconds)

We have a Foo server(foo.something.org), and Bar client uses a HeartBeat thread to periodically connect() and check if its alive or not. This works fine. But every 2 hours, Bar segfaults while trying to resolve the Foo's hostname. 2 hours = 7200…
Kostolma
  • 301
  • 1
  • 4
  • 11
2
votes
2 answers

Segmentation fault in file parsing code

I am getting a segmentation fault when I try to run my program that does matrix addition. I am trying to run the program separately ~1000 times (while timing each run and writing the result to a file). The problem is, I get segmentation fault…
2
votes
3 answers

Segmentation Fault when deploying to handset

I've got a Galaxy Nexus and today it started to give me a Segmentation fault error when deploying to it: [2011-12-07 16:19:17 - Flinders Lite] Android Launch! [2011-12-07 16:19:17 - Flinders Lite] adb is running normally. [2011-12-07 16:19:17 -…
Martyn
  • 16,432
  • 24
  • 71
  • 104
2
votes
6 answers

Segmentation fault upon calling delete

gdb backtrace: #0 0x0040cea9 in free () from /lib/tls/i686/cmov/libc.so.6 #1 0x0033c741 in operator delete(void*) () from /usr/lib/libstdc++.so.6 #2 0x080654b6 in mesh::calculateMeanNormalsPerVertex (this=0x807d684) at…
Rooster
  • 1,267
  • 3
  • 15
  • 23
2
votes
3 answers

warning: format %s expects type char * but argument 2 has type int

I have already looked at other related questions, and none of them helped this case. I am getting the warning listed in the title of my question, and my code for main is as follows: int main( int argc, char *argv[] ) { char *rows; int i, n; …
Mxyk
  • 10,678
  • 16
  • 57
  • 76
2
votes
1 answer

SIGSEGV handler and mprotect and looping effect when injecting instructions at runtime. Handler can't get info->si_addr

I have looked at the various topics relating to this, but couldn't find this specific issue I am having. Things I looked at: Injecting code into executable at runtime C SIGSEGV Handler & Mprotect Can I write-protect every page in the address space…
Setzer
  • 739
  • 4
  • 10
  • 18
2
votes
1 answer

svn_client_checkout3 crashes with EXC_BAD_ACCESS

I want to checkout a working copy: apr_pool_t *pool = NULL; apr_pool_create(&pool, NULL); svn_client_ctx_t *context = NULL; svn_client_create_context(&context, pool); svn_opt_revision_t revision; revision.kind =…
user142019
2
votes
1 answer

Segmentation fault with opendir()?

I can't get to know why do I keep getting this segmentation fault in this function Could anyone enlighten me about how to get rid of it and get my program to work...? Lign 33 : flux = opendir(path); Lign 98 : ret = listdir(env, stock, pos,…
Slrs
  • 105
  • 1
  • 3
  • 11
2
votes
1 answer

Segmentation fault in strtok

I keep getting that error. I am pretty sure it has something to do with memory allocation but i'm not quite sure how to fix it. #include #include #include #include char * VOWELS ="aeiouAEIOU"; void…
livelaughlove
  • 376
  • 3
  • 9
  • 21
2
votes
3 answers

C++: Virtual functions in dynamic shared library produce segfault

in an application I am writing, I am dynamically loading objects from a shared library I wrote. This fine up to a point where virtual functions come into play. This means that I can easily call getters and setters, but I immediately get a…
tapeeR
  • 21
  • 2
2
votes
1 answer

boost variant destructors results in segmentation fault

I faced a problem using a Boost variant. I have a segmentation fault when the variant gets destructed. The weird thing is that this segmentation fault occurs only when I do not activate the optimizations of the compiler (GCC in my case). For…
Baptiste Wicht
  • 7,472
  • 7
  • 45
  • 110
2
votes
0 answers

BOOST_CLASS_EXPORT causes segmentation fault at the end of main()?

I use boost::serialization for my classes. Since I have some inheritance, I have to use BOOST_CLASS_EXPORT to "register" my class. Hope I did not misunderstand anything. I use this macro: BOOST_CLASS_EXPORT(MyClass) Or even I use…
CrBoy
  • 43
  • 4
2
votes
1 answer

CUDA BFS Giant Graph (seg.fault)

I'm making a test on a BFS algorithm on CUDA ( wich I know that has some syncronization problems, but it's part of my work to test it anyway ) but i'm having problems on using (or creating?) 1M+ size graphs. Here's the code I use to create…
GennSev
  • 1,586
  • 4
  • 20
  • 29