From 0d1c8fd9d6407a1c58d329f2b4f53b16494cce84 Mon Sep 17 00:00:00 2001 From: tenderlove Date: Fri, 24 Feb 2012 04:55:33 +0000 Subject: * 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 --- test/psych/test_parser.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test/psych/test_parser.rb') diff --git a/test/psych/test_parser.rb b/test/psych/test_parser.rb index cfbfb61693..d8c53f2d0d 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' -- cgit v1.2.3