summaryrefslogtreecommitdiff
path: root/test/psych/test_parser.rb
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-24 04:55:33 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-24 04:55:33 +0000
commit0d1c8fd9d6407a1c58d329f2b4f53b16494cce84 (patch)
treed13d87d972a2c752adf8191d66c4642bc157f1e9 /test/psych/test_parser.rb
parent0e896b99bffb710fc557a0ccfd25c1d94b89dbc5 (diff)
* 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
Diffstat (limited to 'test/psych/test_parser.rb')
-rw-r--r--test/psych/test_parser.rb30
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'