[Rd] segfault following a detach

From: Izmirlian, Grant (NIH/NCI) [E] <izmirlig_at_mail.nih.gov>
Date: Sat 10 Dec 2005 - 00:28:34 GMT


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,

R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Dec 10 11:35:37 2005

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:34 GMT