diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-10-17 05:21:38 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-10-17 05:21:38 +0000 |
commit | 36862468a80435902ee41c5392d2e3161e5a0281 (patch) | |
tree | 2767693d841f184db2946905a44ecc6d83939914 /test | |
parent | 3f2828078273ec2b92afe27d3b081049bca2bcd2 (diff) | |
download | ruby-36862468a80435902ee41c5392d2e3161e5a0281.tar.gz |
file.c: fix memory leak
* win32/file.c (rb_file_expand_path_internal): fix memory leaks at
a non-absolute home exception.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43328 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_file_exhaustive.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb index 476eced65f..069e5592ca 100644 --- a/test/ruby/test_file_exhaustive.rb +++ b/test/ruby/test_file_exhaustive.rb @@ -519,6 +519,33 @@ class TestFileExhaustive < Test::Unit::TestCase ENV["HOME"] = home end + if /mswin|mingw/ =~ RUBY_PLATFORM + def test_expand_path_home_memory_leak_in_path + assert_no_memory_leak_at_expand_path_home('', 'in path') + end + + def test_expand_path_home_memory_leak_in_base + assert_no_memory_leak_at_expand_path_home('".",', 'in base') + end + + def assert_no_memory_leak_at_expand_path_home(arg, message) + prep = 'ENV["HOME"] = "foo"*100' + assert_no_memory_leak([], prep, <<-TRY, "memory leaked at non-absolute home #{message}") + 10000.times do + begin + File.expand_path(#{arg}"~/a") + rescue ArgumentError => e + next + ensure + abort("ArgumentError (non-absolute home) expected") unless e + end + end + GC.start + TRY + end + end + + def test_expand_path_remove_trailing_alternative_data assert_equal File.join(@rootdir, "aaa"), File.expand_path("#{@rootdir}/aaa::$DATA") assert_equal File.join(@rootdir, "aa:a"), File.expand_path("#{@rootdir}/aa:a:$DATA") |