If I run this script

    require 'tempfile'

    while true
      tempfile = nil
      begin
        tempfile = Tempfile.new('tempfile-test')
      ensure
        tempfile.close(true) unless tempfile.nil?
      end
    end

From a shell in which I've done "ulimit -v 20480" the ruby interpreter
seg faults.  It seems to seg fault when it runs out of memory.

Bumping the resource limit to 80 megabytes doesn't help
-- this script seems to continuously eat up more and more memory.
This is a distilled test case from a real script that processes a
whole lot of input with temp files.

This is under Linux with the latest CVS ruby.

GDB says:

Program received signal SIGSEGV, Segmentation fault.
0x0805b1d5 in backtrace (lev=-1) at eval.c:4803
(gdb) bt
#0  0x0805b1d5 in backtrace (lev=-1) at eval.c:4803
#1  0x0805b418 in make_backtrace () at eval.c:4885
#2  0x08058431 in rb_longjmp (tag=8, mesg=1080758032) at eval.c:3533
#3  0x0805861b in rb_exc_fatal () at eval.c:3576
#4  0x080bf584 in rb_sys_fail (mesg=0x80c2781 "failed to allocate memory")
    at error.c:714
#5  0x08068f7d in mem_error (mesg=0x80c2781 "failed to allocate memory")
    at gc.c:81
#6  0x0806905f in ruby_xmalloc (size=1024) at gc.c:110
#7  0x0809dc96 in ruby_re_compile_pattern (
    pattern=0x8115220 ":in `__getobj__'$", size=17, bufp=0x897ef68)
    at regex.c:2415
#8  0x08093fed in make_regexp (s=0x8115220 ":in `__getobj__'$", len=17, 
    flags=0) at re.c:432
#9  0x08094bf3 in rb_reg_initialize (obj=1080695896, 
    s=0x8115220 ":in `__getobj__'$", len=17, options=0) at re.c:917
#10 0x08094cb3 in rb_reg_new (s=0x8115220 ":in `__getobj__'$", len=17, 
    options=0) at re.c:949
#11 0x08087211 in parse_regx (term=47, paren=47) at parse.y:2599
#12 0x0808bb89 in ruby_yylex () at parse.y:3529
#13 0x08081785 in ruby_yyparse () at /usr/share/bison/bison.simple:595
#14 0x08085b96 in yycompile (f=0x80c06b5 "(eval)", line=1) at parse.y:2148
#15 0x08085d26 in rb_compile_string (f=0x80c06b5 "(eval)", s=1080710392, 
    line=1) at parse.y:2209
#16 0x0805b45e in compile (src=1080710392, file=0x80c06b5 "(eval)", line=1)
    at eval.c:4904
#17 0x0805b75f in eval (self=1080040864, src=1080710392, scope=4, 
    file=0x80c06b5 "(eval)", line=1) at eval.c:4984
#18 0x0805bc4f in rb_f_eval (argc=1, argv=0xbfffb754, self=1080040864)
    at eval.c:5091
#19 0x0805a118 in call_cfunc (func=0x805b9a8 <rb_f_eval>, recv=1080040864, 
    len=-1, argc=1, argv=0xbfffb754) at eval.c:4326
#20 0x0805a621 in rb_call0 (klass=1075628208, recv=1080040864, id=3777, 
    argc=1, argv=0xbfffb754, body=0x401caae0, nosuper=1) at eval.c:4463
#21 0x0805ae38 in rb_call (klass=1075628208, recv=1080040864, mid=3777, 
    argc=1, argv=0xbfffb754, scope=1) at eval.c:4687
#22 0x0805613c in rb_eval (self=1080040864, n=0x401b6980) at eval.c:2680
#23 0x08055672 in rb_eval (self=1080040864, n=0x401b6758) at eval.c:2508
#24 0x08058c98 in rb_yield_0 (val=1079988520, self=1080040864, klass=0, 
    pcall=0) at eval.c:3757
#25 0x08058ec8 in rb_yield (val=1079988520) at eval.c:3826
#26 0x080b4c24 in rb_ary_each (ary=1079993176) at array.c:767
#27 0x0805a126 in call_cfunc (func=0x80b4c04 <rb_ary_each>, recv=1079993176, 
    len=0, argc=0, argv=0x0) at eval.c:4329
#28 0x0805a621 in rb_call0 (klass=1075592928, recv=1079993176, id=3689, 
    argc=0, argv=0x0, body=0x401c39e8, nosuper=1) at eval.c:4463
#29 0x0805ae38 in rb_call (klass=1075592928, recv=1079993176, mid=3689, 
    argc=0, argv=0x0, scope=0) at eval.c:4687
#30 0x08055289 in rb_eval (self=1080040864, n=0x401b8780) at eval.c:2420
#31 0x0805aa12 in rb_call0 (klass=1075553808, recv=1080040864, id=2889, 
    argc=0, argv=0xbfffd4d4, body=0x401b8780, nosuper=0) at eval.c:4591
#32 0x0805ae38 in rb_call (klass=1075553808, recv=1080040864, mid=2889, 
    argc=1, argv=0xbfffd4d0, scope=3) at eval.c:4687
#33 0x08056409 in rb_eval (self=1080040864, n=0x401b6350) at eval.c:2710
#34 0x0805473a in rb_eval (self=1080040864, n=0x401b62d8) at eval.c:2154
#35 0x0805aa12 in rb_call0 (klass=1075553736, recv=1080040864, id=2889, 
    argc=0, argv=0xbfffd678, body=0x401b62d8, nosuper=0) at eval.c:4591
#36 0x0805ae38 in rb_call (klass=1075553736, recv=1080040864, mid=2889, 
    argc=1, argv=0xbfffd674, scope=3) at eval.c:4687
#37 0x08056409 in rb_eval (self=1080040864, n=0x401b82e8) at eval.c:2710
#38 0x0805473a in rb_eval (self=1080040864, n=0x401b9140) at eval.c:2154
#39 0x0805aa12 in rb_call0 (klass=1075552080, recv=1080040864, id=2889, 
    argc=0, argv=0xbfffe468, body=0x401b9140, nosuper=0) at eval.c:4591
#40 0x0805ae38 in rb_call (klass=1075552080, recv=1080040864, mid=2889, 
    argc=1, argv=0xbfffe464, scope=1) at eval.c:4687
#41 0x0805b0d9 in rb_funcall2 (recv=1080040864, mid=2889, argc=1, 
    argv=0xbfffe464) at eval.c:4771
#42 0x0805d6e7 in rb_obj_call_init (obj=1080040864, argc=1, argv=0xbfffe464)
    at eval.c:5799
#43 0x0807c36c in rb_class_new_instance (argc=1, argv=0xbfffe464, 
    klass=1075552080) at object.c:683
#44 0x0805a118 in call_cfunc (func=0x807c324 <rb_class_new_instance>, 
    recv=1075552080, len=-1, argc=1, argv=0xbfffe464) at eval.c:4326
#45 0x0805a621 in rb_call0 (klass=1075628328, recv=1075552080, id=3249, 
    argc=1, argv=0xbfffe464, body=0x401cb4d0, nosuper=1) at eval.c:4463
#46 0x0805ae38 in rb_call (klass=1075628328, recv=1075552080, mid=3249, 
    argc=1, argv=0xbfffe464, scope=0) at eval.c:4687
#47 0x08055f06 in rb_eval (self=1075622784, n=0x401ba388) at eval.c:2667
#48 0x08056ada in rb_eval (self=1075622784, n=0x401ba370) at eval.c:2832
#49 0x080558bd in rb_eval (self=1075622784, n=0x401ba220) at eval.c:2548
#50 0x08054dca in rb_eval (self=1075622784, n=0x401ba1a8) at eval.c:2338
#51 0x080523c8 in eval_node (self=1075622784, node=0x401ba1a8) at eval.c:1082
#52 0x0805276f in ruby_run () at eval.c:1216
#53 0x08050fb2 in main (argc=2, argv=0xbffff954, envp=0xbffff960) at main.c:50
#54 0x4008b65f in __libc_start_main () from /lib/libc.so.6


-- 
matt