From 2bb2310fe51e9ef9c09029a24e3f62f23e0db36a Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 28 May 2015 07:17:55 +0000 Subject: 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 --- test/json/test_json_generate.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/json') 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 -- cgit v1.2.3