From cbf902fc3308290383c8c5e926bf684a23778719 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 28 May 2015 07:17:42 +0000 Subject: parser.rl: allocate structs with wrapper * ext/json/parser/parser.rl (cJSON_parser_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@50660 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/json/test_json.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/json/test_json.rb') diff --git a/test/json/test_json.rb b/test/json/test_json.rb index 46f000148f..96ba744478 100755 --- a/test/json/test_json.rb +++ b/test/json/test_json.rb @@ -560,4 +560,17 @@ EOT assert_equal(Encoding::UTF_8, e.message.encoding, bug10705) assert_include(e.message, json, bug10705) end if defined?(Encoding::UTF_8) + + 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/parser"], + "GC.add_stress_to_class(JSON::Ext::Parser); "\ + "#{code}", code, *rest, rss: true, limit: 1.1, **opt) + end + + def test_no_memory_leak_allocate + assert_no_memory_leak("JSON::Ext::Parser.allocate") + end + end end -- cgit v1.2.3