[R] R unstable and crashes after executing .C

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Feb 21 13:02:20 CET 2007

This really is the wrong list for C programming questions related to R.
See the posting guide and consider R-devel.
See also the debugging advice in 'Writing R Extensions'.

Almost certainly your C code has destroyed R structures, most likely by 
writing outside array bounds.  Running under valgrind should tell you 
about that.

You may or may not get a core dump, but you can run R under gdb.  I 
suspect though that the problem is that an internal gc is crashing.

On Wed, 21 Feb 2007, Sole Acha, Xavi wrote:

> Dear R listers,
> I have developed a C function to be executed from R through the ".C" interface. After doing dyn.load, the function executes properly and I get the results. However, after executing my function, R seems to get unstable and crashes (giving a segmentation fault and exiting) whenever I try to do ANYTHING with a relatively large object (creating a new one or even just writing the name of an existing one).
> I use R 2.4.0 under a Linux machine with 1 GB RAM. Below there is an example of execution, so you can get an idea of what is happening:
> --------------------
> dyn.load("my_C_module.so");
> res <- .C("my_C_function",.....); #The function executes fine and res is ok
> dyn.unload("my_C_module.so") #I know this isn't strictly necessary
> #Here R is still running, but when I execute:
> m <- matrix(0,1000,100); #I try to create a new object and R crashes
> *** caught segfault ***
> address 0x10, cause 'memory not mapped'
> Traceback:
> 1: matrix(0, 1000, 100)
> Possible actions:
> 1: abort (with core dump)
> 2: normal R exit
> 3: exit R without saving workspace
> 4: exit R saving workspace
> --------------------
> Although I tell R to abort and give me the core dump, it doesn't succeed in doing so.
> I would be grateful if anyone could tell me what could be the problem with my C function that makes R behave this way?
> Thank you very much in advance, and apologies for this long email.
> Xavier Solé.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list