Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Segmentation fault but now errors when running Valgrind

7 views
Skip to first unread message

carl

unread,
Nov 28, 2009, 5:24:48 AM11/28/09
to
I have made an application that throws a segmentation fault when I run it.

./MyApp
Segmentation fault

I have then tried to run it with Valgrind:


valgrind --leak-check=yes --track-origins=yes ./MyApp
==8389==
==8389== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 8 from 1)
==8389== malloc/free: in use at exit: 0 bytes in 0 blocks.
==8389== malloc/free: 13,153,309 allocs, 13,153,309 frees,
8,529,290,300 bytes allocated.
==8389== For counts of detected errors, rerun with: -v
==8389== All heap blocks were freed -- no leaks are possible.


So Valgrind cannot find any errors but I still get a segmentation fault when
running the app without Valgrind.

I have used almost a week to go through the code and I have written
unit-test for each part. Any ideas on how to find this error when valgrind
fails to find it or is the just a program that is cursed?


Ian Collins

unread,
Nov 28, 2009, 5:26:35 AM11/28/09
to
carl wrote:
> I have made an application that throws a segmentation fault when I run it.
>
> ./MyApp
> Segmentation fault

What happens when you run the application under a debugger?

--
Ian Collins

carl

unread,
Nov 28, 2009, 6:23:00 AM11/28/09
to

"Ian Collins" <ian-...@hotmail.com> wrote in message
news:7ncc6uF...@mid.individual.net...

I have tried that but the error first appears when a subrutine is called
after 20.000 to 30.000 iterations. I have made something like this:

if (call_count < call_limit) {

//call the failing function
call_count++;
}

When I set call_limit is between 20.000 and 30.000 it works fine but it
varies from call to call.

One possible way would be to put a break inside the above if-statement and
then have a starting count and a end count. But the interval would still be
around a few thousands and my fingers will begin to bleed if I need to press
the skip key in the debugger that many times.

Ian Collins

unread,
Nov 28, 2009, 10:28:08 PM11/28/09
to
carl wrote:
>
> "Ian Collins" <ian-...@hotmail.com> wrote in message
> news:7ncc6uF...@mid.individual.net...
>> carl wrote:
>>> I have made an application that throws a segmentation fault when I
>>> run it.
>>>
>>> ./MyApp
>>> Segmentation fault
>>
>> What happens when you run the application under a debugger?
>>
>
> I have tried that but the error first appears when a subrutine is called
> after 20.000 to 30.000 iterations. I have made something like this:

So? Let it run and let the debugger catch the seg fault.

--
Ian Collins

Ashu

unread,
Nov 29, 2009, 2:37:24 PM11/29/09
to
On Nov 28, 4:23 pm, "carl" <carl@.com> wrote:
> "Ian Collins" <ian-n...@hotmail.com> wrote in message

hey, you might be using some other version of compiler dependent
library.
I faced some problem using libgcc3.2 earlier with my application and
it used to crash. I changed library and it works smooth.

Paavo Helde

unread,
Nov 29, 2009, 6:23:30 PM11/29/09
to
"carl" <carl@.com> wrote in
news:4b10fa77$0$280$1472...@news.sunsite.dk:

> I have made an application that throws a segmentation fault when I run
> it.
>

...

> So Valgrind cannot find any errors but I still get a segmentation
> fault when running the app without Valgrind.

The first thing to try is to run in a debugger and catch the segfault.
Failing that, on Linux/Unix you can generate a core file and load this in
the debugger. One could also try other diagnostic tools like efence.

If all else fails, then you have to start throwing out code from your
program until the segfault goes away, then putting it gradually back again,
pinpointing the problem down.

Strange segfaults can come from memory corruption, or if you have a
multithreaded program, from race conditions. If the segfault appears at
program shutdown, then it is most probably related to static objects'
deinitialization order.

hth
Paavo

Vladimir Jovic

unread,
Dec 1, 2009, 3:49:50 AM12/1/09
to

To add a small details : when it happens, use the backtrace option and
see what caused it.

--
ultrasound www.ezono.com

0 new messages