[Rd] ReleaseLargeFreeVectors SIGSEGV (?) (PR#1008)

Roger.Bivand@nhh.no Roger.Bivand@nhh.no
Mon, 2 Jul 2001 15:27:56 +0200 (MET DST)


Full_Name: Roger Bivand
Version: 1.3.0
OS: GNU/Linux RH6.2, 7.0, Debian 2.2
Submission from: (NULL) (158.37.100.64)


I'm working on interfacing ANN: A Library for Approximate Nearest Neighbor
Searching (http://www.cs.umd.edu/~mount/ANN/) to R, following up a prototype
package I tried in May 2000. ANN is written in C++; my C++ is very weak. Last
year
I didn't experience any problems with memory management, C++ did
its thing, and R did its. I have today recompiled R 1.1.1, and the original
trial
package installs OK, and all the examples can be run repeatedly with no crash.

Could I please ask for confirmation that this problem is on my package's
side and is not a result of the 1.2.0 and later memory handling changes?

I'm now getting replicable segmentation faults in the following context:

(ftp://reclus.nhh.no/pub/R) ann_0.2-2.tar.gz is the old trial package,
ann_0.2-2.pre3.tar.gz is the same with a single change to the shared libs flag
in
the Makefile, and ann_0.2-3.tar.gz is a revision dropping the makefile, since
R now includes C++ in Makeconf.

ann_0.2-3.tar.gz ran through (1.3.0) R CMD check & R CMD build cleanly. 
The examples now trigger the segfault, or it can be triggered in the older 
version by doing in 1.3.0:

> for (i in 1:100) example(ann)

or

> for (i in 1:100) example(nspairs)

or just by:

for (i in 1:100) an1 <- ann(cbind(runif(5000), runif(5000)), k = 4)


The typical gdb listing (shortened) is:

(in this case from)

> for (i in 1:100) example(nspairs)

nspars> an1 <- ann(cbind(runif(1000), runif(1000)), k = 4)

nspars> nspairs(an1)
[1] 311

nspars> an1 <- ann(cbind(runif(1000), runif(1000)), k = 4)

nspars> nspairs(an1)
[1] 304

....


Program received signal SIGSEGV, Segmentation fault.
0x40111109 in chunk_free (ar_ptr=0x401a5d40, p=0x94723a8) at malloc.c:3111
3111	malloc.c: No such file or directory.
(gdb) bt
#0  0x40111109 in chunk_free (ar_ptr=0x401a5d40, p=0x94723a8) at malloc.c:3111
#1  0x40110f9a in __libc_free (mem=0x94727d0) at malloc.c:3023
#2  0x80a6b60 in ReleaseLargeFreeVectors () at memory.c:673
#3  0x80a82b2 in RunGenCollect (size_needed=2000) at memory.c:1079
#4  0x80a9365 in R_gc_internal (size_needed=2000) at memory.c:1669
#5  0x80a9027 in Rf_allocVector (type=14, length=2000) at memory.c:1541
#6  0x808cb58 in Rf_duplicate (s=0x9548498) at duplicate.c:140
#7  0x80660fa in do_makelist (call=0x8a3f7c0, op=0x81a7c00, args=0x8239258, 
    rho=0x824e510) at builtin.c:367
#8  0x809136f in Rf_eval (e=0x8a3f7c0, rho=0x824e510) at eval.c:424
#9  0x8092cf1 in Rf_evalList (el=0x8a3ee30, rho=0x824e510) at eval.c:1171
#10 0x80912f8 in Rf_eval (e=0x8a3f750, rho=0x824e510) at eval.c:422
#11 0x8091089 in Rf_eval (e=0x824037c, rho=0x8240670) at eval.c:368
#12 0x8090ff4 in Rf_eval (e=0x88211a0, rho=0x8240670) at eval.c:345
#13 0x8092cf1 in Rf_evalList (el=0x8821ddc, rho=0x8240670) at eval.c:1171
#14 0x80912f8 in Rf_eval (e=0x8821dc0, rho=0x8240670) at eval.c:422
#15 0x80a4a9d in do_logic2 (call=0x8821c00, op=0x819f3e8, args=0x8821c1c, 
    env=0x8240670) at logic.c:192
#16 0x809119b in Rf_eval (e=0x8821c00, rho=0x8240670) at eval.c:401
#17 0x8091a64 in do_if (call=0x882292c, op=0x8198d74, args=0x8822948, 
    rho=0x8240670) at eval.c:665
#18 0x809119b in Rf_eval (e=0x882292c, rho=0x8240670) at eval.c:401
#19 0x8092394 in do_begin (call=0x8821820, op=0x819e81c, args=0x8821804, 
) at eval.c:887
...

I have also seen:

Program received signal SIGSEGV, Segmentation fault.
0x40111109 in chunk_free (ar_ptr=0x401a5d40, p=0x8ab0b10) at malloc.c:3111
3111	malloc.c: No such file or directory.
(gdb) bt
#0  0x40111109 in chunk_free (ar_ptr=0x401a5d40, p=0x8ab0b10) at malloc.c:3111
#1  0x40110f9a in __libc_free (mem=0x8ab0b18) at malloc.c:3023
#2  0x40312204 in __builtin_vec_delete (ptr=0x8ab0b18)
   from /usr/local/lib/R/library/ann/libs/ann.so
#3  0x40307b5e in annDeallocPts (pa=@0xbfffd7a0) at ANN.cc:124
#4  0x4030733d in ANN_interface (xp=0x8cd8280, eps=@0x8e2a550, qp=0x8e2a5c8, 
    dnn=0x8d727f0, n_pts=@0x8dc7be8, k=@0x8dc7c08, dim=@0x8dc7c28, 
    q_pts=@0x8dc7c48, bucket_size=@0x8dc7c68, insplit=@0x8dc7c88, 
    inshrink=@0x8dc7ca8, priority=@0x8dc7cc8, maxpts=@0x8dc7ce8, nn=0x8ace0d0)
    at ANN_interface.cc:133
#5  0x808a557 in do_dotCode (call=0x8a3f098, op=0x81a7a5c, args=0x8a3d388, 
    env=0x8a4326c) at dotcode.c:1310
#6  0x809136f in Rf_eval (e=0x8a3f098, rho=0x8a4326c) at eval.c:424
#7  0x8092a67 in do_set (call=0x8a3f044, op=0x819e8c4, args=0x8a3f060, 
    rho=0x8a4326c) at eval.c:1092
....


and annDeallocPts() is the C++ deconstructor where:

void annDeallocPts(ANNpointArray &pa)		// deallocate points
{
    delete [] pa[0];				// dealloc coordinate storage
    delete [] pa;				// dealloc points
    pa = NULL;
}


platform i686-pc-linux-gnu
arch     i686             
os       linux-gnu        
system   i686, linux-gnu  
status                    
major    1                
minor    3.0              
year     2001             
month    06               
day      22     
language R
 
[rsb@reclus rsb]$ gcc -v
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux/2.95.3/specs
gcc version 2.95.3 19991030 (prerelease)
[rsb@reclus rsb]$ rpm -q gcc
gcc-2.95.2-7mdk
[rsb@reclus rsb]$ 

(Same on R 1.3.0 on RH70, gcc 2.96-85, Debian 2.2, gcc 2.95.2)

Debian gdb output:

> for (i in 1:10) an1 <- ann(cbind(runif(5000), runif(5000)), k = 4)

Program received signal SIGSEGV, Segmentation fault.
0x400fbb69 in free () from /lib/libc.so.6
(gdb) bt
#0  0x400fbb69 in free () from /lib/libc.so.6
#1  0x400fb9fd in free () from /lib/libc.so.6
#2  0x80a3210 in ReleaseLargeFreeVectors () at memory.c:673
#3  0x80a4932 in RunGenCollect (size_needed=20000) at memory.c:1079
#4  0x80a59bd in R_gc_internal (size_needed=20000) at memory.c:1669
#5  0x80a5687 in Rf_allocVector (type=14, length=20000) at memory.c:1541
#6  0x808a095 in Rf_duplicate (s=0x8fab148) at duplicate.c:140
#7  0x806a479 in ascommon (call=0x8268740, u=0x8fab148, type=18)
    at coerce.c:954


                


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._