I am compiling my application with a third party lib and there seems to be some weird behaviour that suggests a stack overflow issue (this is just a guess).
But when I add a print statement after the line that's crashing the application runs fine. If I remove the print statement (a simple cout << "print something" << endl; statement) the application crashes on a
0x00007f48f2027276 in free () from /lib64/libc.so.6
I tried adding the following char array in place of the print statement and this stopped the crash as well, I then attempted to print the contents of the char array:
char ben[8000] = {0};
memset(&ben, 0, sizeof (ben));
for (int y = 0; y < 8000; ++y)
{
if (ben[y] != 0)
PRINT ("CHAR[%d]=%d", y, ben[y]);
}
to see if anything in the array gets corrupted, but this approach did not work. So I was wondering if there are better ways to detect whether or not this is a stack overflow problem?
I recompiled the application with -fstack-protector-all (both the lib and my code) and this did not turn up anything. I also tried valgrind and it did not give me anything that looked suspicious.
It seems like it's crashing because I'm trying to free an invalid pointer, but I have no idea why the pointer is invalid since it's freeing a local variable (i.e. when it falls out of scope). The pointer is getting corrupted for a reason, but it's a bit like looking for a needle in a haystack. Are there any good techniques to try and converge on this type of problem? Thanks a lot!