Skip to content

Commit 7ea34ee

Browse files
nagachikatmm1
authored andcommitted
merge revision(s) r45350: [Backport ruby#9645]
* variable.c (rb_const_set): delete existing entry on redefinition [Bug ruby#9645] * test/ruby/test_const.rb (test_redefinition): test for leak git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@46301 b2dd03c8-39d4-4d8f-98ff-823fe69b080e Conflicts: ChangeLog version.h
1 parent 04322cb commit 7ea34ee

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

test/ruby/test_const.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: us-ascii -*-
22
require 'test/unit'
3+
require_relative 'envutil'
34

45
class TestConst < Test::Unit::TestCase
56
TEST1 = 1
@@ -54,5 +55,12 @@ def test_redefinition
5455
#{__FILE__}:#{__LINE__-1}: warning: already initialized constant #{c}::X
5556
#{__FILE__}:#{__LINE__-3}: warning: previous definition of X was here
5657
WARNING
58+
code = <<-PRE
59+
olderr = $stderr.dup
60+
$stderr.reopen(File::NULL, "wb")
61+
350000.times { FOO = :BAR }
62+
$stderr.reopen(olderr)
63+
PRE
64+
assert_no_memory_leak([], '', code, 'redefined constant')
5765
end
5866
end

variable.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,8 @@ rb_const_set(VALUE klass, ID id, VALUE val)
22032203
rb_compile_warn(RSTRING_PTR(ce->file), ce->line,
22042204
"previous definition of %"PRIsVALUE" was here", name);
22052205
}
2206+
st_delete(RCLASS_CONST_TBL(klass), &id, 0);
2207+
xfree(ce);
22062208
}
22072209
}
22082210
}

0 commit comments

Comments
 (0)