0

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 ?

  • *To reproduce error, I have to create some dummy objects using new in my code and after certain fixed elements, this seems to fail* -- How about trying to fix your program instead of "preventing segfaults"? Leave the `new` calls in and see what you're doing wrong. – PaulMcKenzie Dec 11 '15 at 19:51
  • @PaulMcKenzie, Are you using multiple threads? – Paulo1205 Dec 11 '15 at 19:54
  • @Paulo1205 I guess you meant this for the OP. – PaulMcKenzie Dec 11 '15 at 19:56
  • @PaulMcKenzie, Oops! You're right... Vinayak, are you using multiple threads? – Paulo1205 Dec 11 '15 at 20:01
  • Hi this is all single threaded at my end of code. It is single threaded in library as well. My first approach was to use gdb to figure out what I am doing wrong and fix it instead of preventing it. However the library writers are not able to reproduce the error hence details about how adding some new statements makes it crash. Issue also being that this does not happen in valgrind and I cannot see any memory corruptions I might be doing. – Vinayak Gagrani Dec 13 '15 at 06:18
  • Library headers used and one to which it was linking were different versions. hence error in read during file. However, Question still remains on tools which can be used to see memory errors in much better way compared to valgrind. – Vinayak Gagrani Dec 16 '15 at 11:37

0 Answers0