# Simple script segfaults 1.8.6-p230

**URL:** <https://www.ruby-forum.com/t/simple-script-segfaults-1-8-6-p230/141473>\
**Category:** Ruby\
**Created:** [June 26, 2008, 6:30am UTC](https://www.ruby-forum.com/t/simple-script-segfaults-1-8-6-p230/141473 "2008-06-26T06:30:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e8c25b/32.png) [@rst](https://www.ruby-forum.com/u/rst)\
**Post date:** [June 26, 2008, 6:30am UTC](https://www.ruby-forum.com/t/simple-script-segfaults-1-8-6-p230/141473/1 "2008-06-26T06:30:23Z")

</div>

When I run the following 10-line ruby script on 1.8.6-p230  
as shipped (built on 32-bit x86 Debian Etch, with configure  
arguments at defaults), it pretty reliably segfaults. My  
patch to get rails working (by reverting changeset 17222  
on the ruby\_1\_8\_6 branch) eliminates this problem as well,  
so this _may_ be the simplest demonstration of the problem  
that’s been killing Rails apps on this Ruby release.

The script:

obj = Object.new

class \<\< obj  
def meth(x, y)  
end  
end

10000.times do  
obj = obj.clone  
end

---

<div class="post-metadata">

**Author:** ![rst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e8c25b/32.png) [@rst](https://www.ruby-forum.com/u/rst)\
**Post date:** [June 26, 2008, 7:00am UTC](https://www.ruby-forum.com/t/simple-script-segfaults-1-8-6-p230/141473/2 "2008-06-26T07:00:53Z")

</div>

On Jun 25, 2008, at 21:28 PM, Robert Thau wrote:

> When I run the following 10-line ruby script on 1.8.6-p230  
> as shipped (built on 32-bit x86 Debian Etch, with configure  
> arguments at defaults), it pretty reliably segfaults. My  
> patch to get rails working (by reverting changeset 17222  
> on the ruby\_1\_8\_6 branch) eliminates this problem as well,  
> so this _may_ be the simplest demonstration of the problem  
> that’s been killing Rails apps on this Ruby release.

It seems that this has been fixed but not backported:

$ ruby18 -v -  
ruby 1.8.7 (2008-06-25 revision 17572) [i686-darwin9.3.0]  
obj = Object.new

class \<\< obj  
def meth(x, y)  
end  
end

10000.times do  
obj = obj.clone  
end  
$ echo $?  
0

p232 crashes for me:

$ ./miniruby -v -  
ruby 1.8.6 (2008-06-24 patchlevel 232) [i686-darwin9.3.0]

[code]  
miniruby(83566) malloc: \*\*\* error for object 0x120a90: double free  
\*\*\* set a breakpoint in malloc\_error\_break to debug  
[…]  
miniruby(83566) malloc: \*\*\* error for object 0x120a90: double free  
\*\*\* set a breakpoint in malloc\_error\_break to debug  
-:9: [BUG] Segmentation fault  
ruby 1.8.6 (2008-06-24) [i686-darwin9.3.0]

Abort trap  
$

Backtrace points to:

Program received signal EXC\_BAD\_ACCESS, Could not access memory.  
Reason: KERN\_INVALID\_ADDRESS at address: 0xc000000f  
st\_free\_table (table=0x120c90) at st.c:211  
211 next = ptr-\>next;  
(gdb) bt  
#0 st\_free\_table (table=0x120c90) at st.c:211  
#1 0x000363ae in garbage\_collect () at gc.c:1177  
#2 0x00036695 in rb\_newobj () at gc.c:384  
#3 0x0005718c in rb\_node\_newnode (type=NODE\_METHOD, a0=1182448,  
a1=1182448, a2=1182448) at parse.y:4520  
#4 0x0000c01a in clone\_method (mid=3221225475, body=0x20006c,  
data=0xbfffe248) at class.c:70  
#5 0x00085b81 in st\_foreach (table=0x176c40, func=0xbfe0  
\<clone\_method\>, arg=3221217864) at st.c:487  
#6 0x0000cc63 in rb\_singleton\_class\_clone (obj=\<value temporarily  
unavailable, due to optimizations\>) at class.c:160
