diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-27 08:02:28 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-27 08:02:28 +0000 |
commit | d0fb46b096e8268b97b949d0c9c6642738e6174f (patch) | |
tree | 070f03193ada1f335cd8bc5870a929aa9f5242a3 /test | |
parent | df5c989ae93b85663075a1c696d98979908dd998 (diff) | |
download | ruby-d0fb46b096e8268b97b949d0c9c6642738e6174f.tar.gz |
bigdecimal.c: wrapper object before alloc
* ext/bigdecimal/bigdecimal.c (VpNewRbClass): make wrapper object
before result structs allocation and manage refcount for each
elements to get rid of potential memory leak.
* ext/bigdecimal/bigdecimal.c (BigDecimal_global_new): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/bigdecimal/test_bigdecimal.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index 042d11da0f..ad48d70799 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -1552,4 +1552,31 @@ class TestBigDecimal < Test::Unit::TestCase Thread.current.keys.to_s EOS end + + def assert_no_memory_leak(code, *rest, **opt) + code = "5.times {1_000.times {begin #{code}; rescue NoMemoryError; end; GC.start}} if b" + super(["-rbigdecimal"], + "b = BigDecimal('10'); b.nil?; " \ + "GC.add_stress_to_class(BigDecimal); "\ + "#{code}", code, *rest, rss: true, **opt) + end + + if EnvUtil.gc_stress_to_class? + def test_no_memory_leak_allocate + assert_no_memory_leak("BigDecimal.allocate") + end + + def test_no_memory_leak_initialize + assert_no_memory_leak("BigDecimal.new") + end + + def test_no_memory_leak_global_new + assert_no_memory_leak("BigDecimal('10')") + assert_no_memory_leak("BigDecimal(b)") + end + + def test_no_memory_leak_create + assert_no_memory_leak("b + 10") + end + end end |