-3

It seems that changing the version of gcc I use from gcc 4.7.3 to gcc 4.9.2 causes a segfault for my project (after a clean build and run).

In an unfortunate turn of events gdb is broken on the server I am getting this error on and can't use it for now. Any known changes in gcc itself that could cause this? I suspect the issue is potentially caused by a double free.

paul-g
  • 3,797
  • 2
  • 21
  • 36
  • 4
    Have you tried `valgrind`? – Šimon Tóth Aug 10 '15 at 11:22
  • 7
    Most likely, there is some UB in your code, like the guessed one, double free. It is almost impossible to conclude anything without seeing the code. – Sourav Ghosh Aug 10 '15 at 11:24
  • In summary the diff that is causing this adds a pointer member to a class. The pointer is set but _never_ used. This seems like a very strange thing to cause a segfault, so I assumed that perhaps gcc is trying to generate a destructor for that object calling free on the pointer. Is this possible? Is there a change in the way destructors are being generated between 4.7 and 4.9? – paul-g Aug 10 '15 at 11:31
  • Consider also this http://stackoverflow.com/questions/1177457/debug-heap-stl-debugging-equivalent-for-gcc – Ben Aug 10 '15 at 11:41

1 Answers1

3

You should try to use valgrind.

Valgrind is a debugging tool only requiring for your code to be compiled with the -g flag. It's the best way to spot segmentation fault over a program, or any memory leak.

Think about using valgrind options while debugging (it's at the bottom of the valgrind report) something like leak-checkfull (I'm not able to run valgrind right now so I can't tell you exactly what it is).

But whenever I compile my code, I use valgrind with it to check every possible failure. Consider even putting VG in your Makefile rules for more simplicity.

Xcrowzz
  • 182
  • 1
  • 19
  • Ok, thanks, using valgrind helped me find the source of the double free, which is an undefined behaviour as suggested above. http://stackoverflow.com/questions/13685240/malloc-double-free-behaviour – paul-g Aug 10 '15 at 11:54