2

Sorry, I'm new to c programming

As the title says, The code runs perfectly till the end of main where it returns 0. It then gives a seg fault with no reason why. Some answers said that maybe I wasnt freeing all that I malloced but I did. So I tried using gdb to figure out why. This was the first time I've ever used it.

This is the output:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7644f1d in ?? () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0  0x00007ffff7644f1d in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007ffff76450aa in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x00007ffff760365b in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#3  0x00007ffff76036f5 in exit () from /lib/x86_64-linux-gnu/libc.so.6
#4  0x00007ffff75eaecc in __libc_start_main ()
   from /lib/x86_64-linux-gnu/libc.so.6
#5  0x0000000000400bc9 in _start ()

My main:

int main(int argc, char *argv[]) {

    if(argv[1] == NULL)
    {
        printf("Please enter the path to the map generating file as an argument.\n");
        exit(0);
    }

    run(getName(), argv[1]);
    return 0;
}

My program is a ncurses program, which i can (I believe I am) succesfully create the screen and then close it. I've checked that all the malloced variables have been freed as well.

Run is in a diffrent c file where I draw the ncurses board.

Any help would be appreciated.

Exikle
  • 1,155
  • 2
  • 18
  • 42

1 Answers1

0

It's not sure that gdb will give you the exact location when the corruption really happens. (the backtrace suggests it's a stack-related one)

For this kind of errors, the best tool is Valgrind, run your app with it.

(In my experience memory corruption errors could be tracked down and eliminated within minutes with Valgrind)

lorenzodarkside
  • 146
  • 2
  • 4