Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot access memory at address error

Tags:

c++

I'm getting this error:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000407265 in Quadtree::deeper (this=0x7fffffffe430, 
    orig=@0x7fffffffe430, n=@0x7a1da0, tol=Cannot access memory at address 0x7fffff3feffc
) at quadtree.cpp:47
47      int Quadtree::deeper(QuadtreeNode * & orig, QuadtreeNode * & n, int tol, int tolNum) {

This is line 47:

int Quadtree::deeper(QuadtreeNode * & orig, QuadtreeNode * & n, int tol, int tolNum) {

Whats weird is that I am not getting any valgrind errors at all, but only gdb error and seg fault at run time. What can this error possibly mean in a general sense (without having to see the rest of my code)?

like image 503
Snowman Avatar asked Apr 01 '11 23:04

Snowman


1 Answers

My best guess: you are seeing a stack overflow (What a coincidence, given the site we're on! :). I can't explain why Valgrind isn't catching it though: usually Valgrind uses the same stack size as the OS (at least on my system).

What this error means is that your code tried to access memory at address 0x7fffff3feffc -- either a read or a write, but that address is not currently memory-mapped into your address space. The instruction that performed this illegal read or write was at memory address 0x0000000000407265.

If the compiler gives you the line number of your function's opening brace as the offending line, it might be in the function's prologue (the part that saves registers to the stack). That's why I suspect you have a stack overflow.

On Linux, you can look at /proc/YOUR-PID/maps to get a memory-map for the entire process. It will show you where the stack and heap are stored, as well as where the libraries are loaded. You could use this information to figure out what part of memory you've likely overflowed. Since the stack is usually (on Linux) placed at the very top of memory, you'll probably find that this very large address is very near to your stack.

Good luck!

like image 183
Josh Haberman Avatar answered Oct 19 '22 04:10

Josh Haberman