diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-03-17 01:24:06 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-03-17 01:24:06 +0000 |
commit | 3e6fe414d80dacb88bbaf11853db03a44e5d024c (patch) | |
tree | b79ad1d8d2dd55ed35f0e6ada12e7abba273193c | |
parent | 2be728c45f38aba8473e4c2905709cc1d559aeb2 (diff) |
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
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | test/ruby/test_const.rb | 8 | ||||
-rw-r--r-- | variable.c | 2 |
3 files changed, 16 insertions, 0 deletions
@@ -1,3 +1,9 @@ +Mon Mar 17 10:11:59 2014 Eric Wong <e@80x24.org> + + * 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@zzak.io> * lib/time.rb: [DOC] Fix timezone in example of Time.parse [Bug #9521] diff --git a/test/ruby/test_const.rb b/test/ruby/test_const.rb index dab45b7e08..c4a4d93249 100644 --- a/test/ruby/test_const.rb +++ b/test/ruby/test_const.rb @@ -1,5 +1,6 @@ # -*- 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 #{__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 diff --git a/variable.c b/variable.c index c97c210af1..079f862797 100644 --- a/variable.c +++ b/variable.c @@ -2203,6 +2203,8 @@ rb_const_set(VALUE klass, ID id, VALUE val) 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); } } } |