[R] help debugging segfaults

Thomas Lumley tlumley@u.washington.edu
Thu, 13 Jun 2002 09:05:13 -0700 (PDT)

On Thu, 13 Jun 2002, Liaw, Andy wrote:
> Everyone suggested using some malloc debugger (such as Electric Fence).  All
> I did was following half of what BDR suggested below, i.e., changing all the
> S_alloc() calls to Calloc() and Free().  I didn't get to try efence, and the
> problem seems to have disappeared!

No, the *symptoms* have disappeared. This is not necessarily an

> As I read it from the R-exts manual, the difference between S_alloc and
> Calloc is that S_alloc takes memory from the heap, whereas Calloc takes
> memory addtional to the heap.  So can anyone explain what's going on?  It's
> still kind of mysterious to me...

It looked as if your code was writing to/reading from memory that didn't
belong to it. What happens then depends on who the memory does belong to,
and what they are doing with it. There's no guarantee that just because it
doesn't crash today that it won't in the future, or worse, start giving
subtly wrong answers.

A segmentation fault is a good thing in this context -- it's a sign that
the operating system has protected you from the consequences of your
actions by killing the program.


r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch