Hi all. I'm new to C++ and I've run into a problem I can't solve, so I was wondering if I could get some help. I was writing a program and it started crashing on exit (segment fault), after the 'return 0' in main(). I figure it's an std destructor but beyond that I have no idea.
Forgive the odd state of the code below. I started with the program I was writing and just stripped out as much as I could, while making sure the crash persisted. If I remove any of the remaining code the crash disappears, even the seemly unrelated or scoped code. The problem is that I don't know what is causing it. Can anyone spot an error?
You set std::clog to use the stream buffer of logfile but logfile will be destructed before std::clog so std::clog ends up with a stream buffer pointer that is no longer valid. Calling std::clog.rdbuf(nullptr); before main() ends fixes the problem.
I would never have figured that out, well, maybe in a few weeks. I thought it was something to do with the mutex or conditional. Thank you so much Peter.