diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-02-27 17:21:00 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-02-27 17:21:00 -0800 |
commit | 3ef54d1b36bfec75f0eb6c9de8c9cb5e71d25bcd (patch) | |
tree | 08128ce82bd80dfed4251d6d00c3a72372f2163c /test | |
parent | 9eb12645b1ab380db738029edcf08cf1c4220607 (diff) | |
download | psych-3ef54d1b36bfec75f0eb6c9de8c9cb5e71d25bcd.zip |
* ext/psych/parser.c: prevent a memory leak by protecting calls to
handler callbacks.
* test/psych/test_parser.rb: test to demonstrate leak.
Diffstat (limited to 'test')
-rw-r--r-- | test/psych/test_parser.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/psych/test_parser.rb b/test/psych/test_parser.rb index cfbfb61..d8c53f2 100644 --- a/test/psych/test_parser.rb +++ b/test/psych/test_parser.rb @@ -32,6 +32,36 @@ module Psych @handler.parser = @parser end + def test_exception_memory_leak + yaml = <<-eoyaml +%YAML 1.1 +%TAG ! tag:tenderlovemaking.com,2009: +--- &ponies +- first element +- *ponies +- foo: bar +... + eoyaml + + [:start_stream, :start_document, :end_document, :alias, :scalar, + :start_sequence, :end_sequence, :start_mapping, :end_mapping, + :end_stream].each do |method| + + klass = Class.new(Psych::Handler) do + define_method(method) do |*args| + raise + end + end + + parser = Psych::Parser.new klass.new + 2.times { + assert_raises(RuntimeError, method.to_s) do + parser.parse yaml + end + } + end + end + def test_multiparse 3.times do @parser.parse '--- foo' |