ruby-changes:33271
From: normal <ko1@a...>
Date: Mon, 17 Mar 2014 10:24:14 +0900 (JST)
Subject: [ruby-changes:33271] normal:r45350 (trunk): variable.c: avoid memory leak on const redefinition
normal 2014-03-17 10:24:06 +0900 (Mon, 17 Mar 2014) New Revision: 45350 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45350 Log: variable.c: avoid memory leak on const redefinition * variable.c (rb_const_set): delete existing entry on redefinition [Bug #9645] * test/ruby/test_const.rb (test_redefinition): test for leak Modified files: trunk/ChangeLog trunk/test/ruby/test_const.rb trunk/variable.c Index: ChangeLog =================================================================== --- ChangeLog (revision 45349) +++ ChangeLog (revision 45350) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Mar 17 10:11:59 2014 Eric Wong <e@8...> + + * variable.c (rb_const_set): delete existing entry on redefinition + [Bug #9645] + * test/ruby/test_const.rb (test_redefinition): test for leak + Sun Mar 16 21:33:01 2014 Zachary Scott <e@z...> * lib/time.rb: [DOC] Fix timezone in example of Time.parse [Bug #9521] Index: variable.c =================================================================== --- variable.c (revision 45349) +++ variable.c (revision 45350) @@ -2203,6 +2203,8 @@ rb_const_set(VALUE klass, ID id, VALUE v https://github.com/ruby/ruby/blob/trunk/variable.c#L2203 rb_compile_warn(RSTRING_PTR(ce->file), ce->line, "previous definition of %"PRIsVALUE" was here", name); } + st_delete(RCLASS_CONST_TBL(klass), &id, 0); + xfree(ce); } } } Index: test/ruby/test_const.rb =================================================================== --- test/ruby/test_const.rb (revision 45349) +++ test/ruby/test_const.rb (revision 45350) @@ -1,5 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_const.rb#L1 # -*- coding: us-ascii -*- require 'test/unit' +require_relative 'envutil' class TestConst < Test::Unit::TestCase TEST1 = 1 @@ -54,5 +55,12 @@ class TestConst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_const.rb#L55 #{__FILE__}:#{__LINE__-1}: warning: already initialized constant #{c}::X #{__FILE__}:#{__LINE__-3}: warning: previous definition of X was here WARNING + code = <<-PRE +olderr = $stderr.dup +$stderr.reopen(File::NULL, "wb") +350000.times { FOO = :BAR } +$stderr.reopen(olderr) +PRE + assert_no_memory_leak([], '', code, 'redefined constant') end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/