From a763e3460f594f60a5d2e8eba5f7da981d717a55 Mon Sep 17 00:00:00 2001 From: ko1 Date: Thu, 29 Nov 2018 08:03:55 +0000 Subject: clear dst Hash on Hash#replace. [Bug #15358] * hash.c (linear_copy): solve two issues on `Hash#replace`. (1) fix memory leak (1-1) don't allocate memory if destination already has a memory area. (1-2) free destination memory if src is NULL. (2) clear transient heap flag if src is NULL. [Bug #15358] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66091 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_hash.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/ruby/test_hash.rb') diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 03ebd38f1f..7db3c27f87 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -755,6 +755,14 @@ class TestHash < Test::Unit::TestCase assert_predicate(h, :compare_by_identity?) end + def test_replace_bug15358 + h1 = {} + h2 = {a:1,b:2,c:3,d:4,e:5} + h2.replace(h1) + GC.start + assert(true) + end + def test_shift h = @h.dup -- cgit v1.2.3