diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-28 07:17:55 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-28 07:17:55 +0000 |
commit | 2bb2310fe51e9ef9c09029a24e3f62f23e0db36a (patch) | |
tree | b30523e0cfc87534bbb6cd19e218e14fbf4e3611 /test | |
parent | 60b0c53ea28606e2d0e2c7ab22978792a4f52189 (diff) | |
download | ruby-2bb2310fe51e9ef9c09029a24e3f62f23e0db36a.tar.gz |
generator.c: allocate structs with wrapper
* ext/json/generator/generator.c (cState_s_allocate): allocate
structs with making new wrapper objects and get rid of potential
memory leak.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50661 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/json/test_json_generate.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/test/json/test_json_generate.rb b/test/json/test_json_generate.rb index 1834290944..ce470db3c2 100644 --- a/test/json/test_json_generate.rb +++ b/test/json/test_json_generate.rb @@ -344,4 +344,17 @@ EOT assert_equal '[""]', JSON.generate([s.new]) end end + + if EnvUtil.gc_stress_to_class? + def assert_no_memory_leak(code, *rest, **opt) + code = "8.times {20_000.times {begin #{code}; rescue NoMemoryError; end}; GC.start}" + super(["-rjson/ext/generator"], + "GC.add_stress_to_class(JSON::Ext::Generator::State); "\ + "#{code}", code, *rest, rss: true, limit: 1.1, **opt) + end + + def test_no_memory_leak_allocate + assert_no_memory_leak("JSON::Ext::Generator::State.allocate") + end + end end |