From: Roman Shterenzon Date: 2008-10-25T23:09:22+09:00 Subject: [ruby-core:19507] Possible memory leak when using $KCODE='u' --0-400979337-1224943369=:71518 Content-Type: text/plain; charset=us-ascii Good day, While trying to write some indexing application, I've found that my application runs out of memory. I followed the instructions on http://blog.evanweaver.com/articles/2008/02/05/valgrind-and-ruby/ and below you can see my findings. I suspect that there is some memory leak in regexp which occurs when setting $KCODE='u' I narrowed down this problem to this code: #!/usr/bin/ruby $KCODE='u' class TestMem def testme page = 'Test' page.match(%r{(.*?)}i) end end t = TestMem.new t.testme Below is the output of valgrind (when running against my app, it shows larger amounts of leaked memory): ==22373== 8 bytes in 1 blocks are definitely lost in loss record 1 of 30 ==22373== at 0x4006AEE: malloc (vg_replace_malloc.c:207) ==22373== by 0x80B8835: ruby_re_compile_pattern (regex.c:2480) ==22373== by 0x80AA112: make_regexp (re.c:643) ==22373== by 0x80AB426: rb_reg_initialize (re.c:1376) ==22373== by 0x80AB559: rb_reg_new (re.c:1410) ==22373== by 0x809953F: ruby_yyparse (parse.y:2003) ==22373== by 0x809AC4D: yycompile (parse.y:2624) ==22373== by 0x809AF83: rb_compile_file (parse.y:2716) ==22373== by 0x80C20BC: load_file (ruby.c:967) ==22373== by 0x80C1C40: proc_options (ruby.c:843) ==22373== by 0x80C2694: ruby_process_options (ruby.c:1236) ==22373== by 0x8054B61: ruby_options (eval.c:1539) ..snip.. (Skipping, since all of reports list memory that was assigned to bufp structure in regex.c: ruby_re_compile_pattern) ==22373== 1,024 bytes in 1 blocks are definitely lost in loss record 26 of 30 ==22373== at 0x4006AEE: malloc (vg_replace_malloc.c:207) ==22373== by 0x80B8723: ruby_re_compile_pattern (regex.c:2467) ==22373== by 0x80AA112: make_regexp (re.c:643) ==22373== by 0x80AB426: rb_reg_initialize (re.c:1376) ==22373== by 0x80AB559: rb_reg_new (re.c:1410) ==22373== by 0x809953F: ruby_yyparse (parse.y:2003) ==22373== by 0x809AC4D: yycompile (parse.y:2624) ==22373== by 0x809AF83: rb_compile_file (parse.y:2716) ==22373== by 0x80C20BC: load_file (ruby.c:967) ==22373== by 0x80C1C40: proc_options (ruby.c:843) ==22373== by 0x80C2694: ruby_process_options (ruby.c:1236) ==22373== by 0x8054B61: ruby_options (eval.c:1539) This doesn't happen if I remove the $KCODE='u' Is it a real memory leak? Thank you in advance, --Roman --0-400979337-1224943369=:71518 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
Good day,

While trying to= write some indexing application, I've found that my application runs out o= f memory.
I followed the instructions on=A0http://blog.evanweaver= .com/articles/2008/02/05/valgrind-and-ruby/ and below you can see my findin= gs.
I suspect that there is some memory leak in regexp which occu= rs when setting $KCODE=3D'u'
I narrowed down this problem to this= code:

#!/usr/bin/ruby
$KCODE=3D'u'=

class TestMem
=A0=A0def testme
=A0=A0 =A0 =A0 =A0page =3D '<html><head><title>Test</title>&l= t;/head><body></body></html>'
=A0=A0 =A0 =A0 =A0page.mat= ch(%r{<title>(.*?)</title>}i)
=A0=A0end
end
=
t =3D TestMem.new
t.testme

Below is the outpu= t of valgrind (when running against my app, it shows larger amounts of leak= ed memory):
=3D=3D22373=3D=3D 8 bytes in 1 blocks are defini= tely lost in loss record 1 of 30
=3D=3D22373=3D=3D =A0 =A0at 0x40= 06AEE: malloc (vg_replace_malloc.c:207)
=3D=3D22373=3D=3D =A0 =A0= by 0x80B8835: ruby_re_compile_pattern (regex.c:2480)
=3D=3D22373= =3D=3D =A0 =A0by 0x80AA112: make_regexp (re.c:643)
=3D=3D22373=3D= =3D =A0 =A0by 0x80AB426: rb_reg_initialize (re.c:1376)
=3D=3D2237= 3=3D=3D =A0 =A0by 0x80AB559: rb_reg_new (re.c:1410)
=3D=3D22373= =3D=3D =A0 =A0by 0x809953F: ruby_yyparse (parse.y:2003)
=3D=3D223= 73=3D=3D =A0 =A0by 0x809AC4D: yycompile (parse.y:2624)
=3D=3D2237= 3=3D=3D =A0 =A0by 0x809AF83: rb_compile_file (parse.y:2716)
=3D= =3D22373=3D=3D =A0 =A0by 0x80C20BC: load_file (ruby.c:967)
=3D=3D= 22373=3D=3D =A0 =A0by 0x80C1C40: proc_options (ruby.c:843)
=3D=3D= 22373=3D=3D =A0 =A0by 0x80C2694: ruby_process_options (ruby.c:1236)
=3D=3D22373=3D=3D =A0 =A0by 0= x8054B61: ruby_options (eval.c:1539)

..snip.. (Ski= pping, since all of reports list memory that was assigned to bufp structure= in regex.c:=A0ruby_re_compile_pattern)

=3D= =3D22373=3D=3D 1,024 bytes in 1 blocks are definitely lost in loss record 2= 6 of 30
=3D=3D22373=3D=3D =A0 =A0at 0x4006AEE: malloc (vg_replace= _malloc.c:207)
=3D=3D22373=3D=3D =A0 =A0by 0x80B8723: ruby_re_com= pile_pattern (regex.c:2467)
=3D=3D22373=3D=3D =A0 =A0by 0x80AA112= : make_regexp (re.c:643)
=3D=3D22373=3D=3D =A0 =A0by 0x80AB426: r= b_reg_initialize (re.c:1376)
=3D=3D22373=3D=3D =A0 =A0by 0x80AB55= 9: rb_reg_new (re.c:1410)
=3D=3D22373=3D=3D =A0 =A0by 0x809953F: = ruby_yyparse (parse.y:2003)
=3D=3D22373=3D=3D =A0 =A0by 0x809AC4D= : yycompile (parse.y:2624)
=3D=3D22373=3D=3D =A0 =A0by 0x809AF83:= rb_compile_file (parse.y:2716)
=3D=3D22373=3D=3D =A0 =A0by 0x80C= 20BC: load_file (ruby.c:967)
=3D=3D22373=3D=3D =A0 =A0by 0x80C1C40: proc_options= (ruby.c:843)
=3D=3D22373=3D=3D =A0 =A0by 0x80C2694: ruby_process= _options (ruby.c:1236)
=3D=3D22373=3D=3D =A0 =A0by 0x8054B61: rub= y_options (eval.c:1539)

This doesn't happen if I r= emove the $KCODE=3D'u'
Is it a real memory leak?

Thank you in advance,
--Roman

=0A=0A=0A=0A --0-400979337-1224943369=:71518--