I am using a library which seems to read from a compressed file line by line via a buffer. It seems to crash in BZ2_bzRead in gdb but not in valgrind when i have 3 instances of such reader objects reading different files. I have checked that buffer, file pointer are both valid at the point of function call in gdb.
To reproduce error, I have to create some dummy objects using new in my code and after certain fixed elements, this seems to fail. If I dont do this then it seems to run perfectly fine.
At first, I thought that i corrupt heap in some way but valgrind does not seem to catch any such in memcheck. it only reports some uninitialised calls on fabs and lround (there does not seem to be any such parameter as far as i could tell).
Is there any way to prevent segfault in ferror and capture it before hand using try catch or valgrind or gdb or some other mechanism to see memory violations ?