[Rd] segfault following a detach

Byron Ellis ellis at stat.harvard.edu
Sat Dec 10 06:58:21 CET 2005


That sounds like your C function is smashing some of the header  
information in a chunk of memory somewhere past res2 so that cleanup  
during quit fails.

On Dec 9, 2005, at 4:28 PM, Izmirlian, Grant (NIH/NCI) [E] wrote:

> Jim:
>
> This reminds me of problems I've had before, but usually they occur  
> when I quit R
> i.e. q(), because when testing and developing I can't remember  
> actually detaching
> a package. I can however think of countless times I get a  
> segmentation fault upon
> quiting R. Usually this boils down to a hidden return argumen that  
> is given an
> insufficient allocation of memory. For example
>
>   "foo" <- function(x, y, z){
>      nx <- length(x)
>      ny <- length(y)
>      nz <- length(z)
>      ans <- .C("bar",
>             x = as.double(x),
>             y = as.double(y),
>             z = as.double(z),
>             res1 = as.double(rep(0, nx)),
>             res2 = as.double(rep(0, nx*ny)),
>             PACKAGE = "FooBar")
>      list(result = asn$res1)
> }
>
> Notice that only ans$res1 is returned so that it is easy to forget  
> about ans$res2,
> as I have often done! Now suppose that the C routine actually needs  
> nx*ny*nz space
> (say) for the pointer to double at the position indicated by res2  
> instead of just
> the nx*ny provided. Although you would expect a segmentation fault  
> at runtime, it
> is my experience that sometimes the function completes and the  
> segmentation fault
> doesn't happen until I quit R.
>
> I hope that these comments are helpful,
>
> Grant Izmirlian,
> NCI
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

---
Byron Ellis (ellis at stat.harvard.edu)
"Oook" -- The Librarian



More information about the R-devel mailing list