[R] Segmentation fault

Prof Brian Ripley ripley at stats.ox.ac.uk
Sun Nov 4 15:23:57 CET 2001

On Sun, 4 Nov 2001, [iso-8859-1] Göran Broström wrote:

> Dear R-afficionados,
> I have made a package that uses compiled C code, and I use the
> Calloc/Free mechanism in that code. When I run a function calling
> the C code, everything is fine, but when I run it once more I get
> ('R -d gdb', RH 7.2, R-1.3.1):
> > te()
> Program received signal SIGSEGV, Segmentation fault.
> RunGenCollect (size_needed=41992) at memory.c:1007
> 1007			SEXP next = NEXT_NODE(s);
> My guess is that I haven't Free'd enough in the C code. Before I start
> searching, I would like to have an expert opinion. Could the reason be
> something else?

You can't Free() too little.  You can Free() too much.  That is, not
freeing memory merely gives a memory leak, but freeing unallocated memory
corrupts the memory management system.  One way to check this is to zero
pointers initially. As Free zeroes them, check before calling Free that
you have a non-NULL pointer.

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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

r-help 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-help-request at stat.math.ethz.ch

More information about the R-help mailing list