* ext/psych/parser.c: prevent a memory leak by protecting calls to

handler callbacks.
* test/psych/test_parser.rb: test to demonstrate leak.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34783 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tenderlove 2012-02-24 04:55:33 +00:00
parent 0e896b99bf
commit 0d1c8fd9d6
3 changed files with 154 additions and 23 deletions

View file

@ -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'