diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-28 07:17:42 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-05-28 07:17:42 +0000 |
commit | cbf902fc3308290383c8c5e926bf684a23778719 (patch) | |
tree | dc15beb24155ca79411233af59b3b96154032a88 /test | |
parent | 828de1a06d556d2f1f657f948f9d33a562957fba (diff) | |
download | ruby-cbf902fc3308290383c8c5e926bf684a23778719.tar.gz |
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
Diffstat (limited to 'test')
-rwxr-xr-x | test/json/test_json.rb | 13 |
1 files changed, 13 insertions, 0 deletions
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 |