summaryrefslogtreecommitdiff
path: root/test/json
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-28 07:17:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-28 07:17:55 +0000
commit4d059bf9f5f10f3d3088de49fc87e5555db7770d (patch)
treeb30523e0cfc87534bbb6cd19e218e14fbf4e3611 /test/json
parentcbf902fc3308290383c8c5e926bf684a23778719 (diff)
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/json')
-rw-r--r--test/json/test_json_generate.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/json/test_json_generate.rb b/test/json/test_json_generate.rb
index 1834290..ce470db 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