From e89d80702bd98a8276243a7fcaa2a158b3bfb659 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 27 Jan 2022 00:28:39 +0900 Subject: Fix memory leak at the same named alias [Bug #18516] When aliasing a method to the same name method, set a separate bit flag on that method definition, instead of the reference count increment. Although this kind of alias has no actual effect at runtime, is used as the hack to suppress the method re-definition warning. --- test/ruby/test_alias.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_alias.rb b/test/ruby/test_alias.rb index c6fad25cc2..99f2223b49 100644 --- a/test/ruby/test_alias.rb +++ b/test/ruby/test_alias.rb @@ -264,4 +264,22 @@ class TestAlias < Test::Unit::TestCase end end; end + + def test_alias_memory_leak + assert_no_memory_leak([], "#{<<~"begin;"}", "#{<<~'end;'}", rss: true) + begin; + class A + 500.times do + 1000.times do |i| + define_method(:"foo_#{i}") {} + + alias :"foo_#{i}" :"foo_#{i}" + + remove_method :"foo_#{i}" + end + GC.start + end + end + end; + end end -- cgit v1.2.3