I have an interesting Segmentation Fault. It occurs at an unknown place in my code. The code is fairly simple, two objects, and one general function. The function is supposed to create a graph of the objects. When I run the code with just a main calling the function, I get a seg fault and the following line of code in GDB.
Program received signal SIGSEGV, Segmentation fault. 0x00007ffff758a02c in free () from /lib/x86_64-linux-gnu/libc.so.6
When I add a line into the main right before the function call that is simply cout << "Check"; I still get a segmentation fault, but the check does not appear in output. Really lost here. What should I try next?
EDIT:
Thanks for the help with using flush. I've found the area in the code that's causing the seg fault. The functions I'm using are new to me though so I'm still a little lost. Anyone see a bug?
const char* inFile = inFileP.c_str();
list<CContinent> world;
CCountry *homeCountry = new CCountry;
CCountry *neighborCountry = new CCountry;
fstream filestr;
filestr.open(inFile, fstream::in | fstream::out | fstream::app);
string line;
std::cout << "Check" << std::flush;
otherwise you're not guaranteed to get any output. - Joseph Mansfieldvalgrind
. There's a possibility that you're corrupting something in one place, and then then accessing the corrupted memory in a way that generates the segfault, such as dereferencing junk as a pointer. - Phil Miller