[Rcpp-devel] [Segfault Reason] Beginner Question: Same code *sometimes* fails due to segfault sometimes

Davor Cubranic cubranic at stat.ubc.ca
Sat May 21 01:39:37 CEST 2011


On 2011-05-20, at 12:59 AM, Sunny Srivastava wrote:

> My code sometimes fails with a segmentation fault error, however this behavior cannot be replicated. That is, most of the times it runs fine and gives appropriate results, but once in a while it will fail due to segmentation fault and gives error like -- 
> 
>  *** caught segfault ***
> address 0x18, cause 'memory not mapped'
> 
> I don't think this is normal, but how can it give correct answers when it runs correctly. Any ideas?

It's sheer chance that your code is not segfaulting every time it's running. This error means your program is trying to access memory that does not belong to it. Something that was allocated was freed, or it was never allocated in the first place, but is still being accessed.

As Romain suggested, post the code that causes this. If it's really long, try to narrow it down to a small reproducible example. 

Davor



More information about the Rcpp-devel mailing list