1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2013-10-17 05:21:38 +00:00
parent 3f28280782
commit 36862468a8
3 changed files with 34 additions and 0 deletions

View file

@ -1,3 +1,8 @@
Thu Oct 17 14:21:34 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/file.c (rb_file_expand_path_internal): fix memory leaks at
a non-absolute home exception.
Thu Oct 17 14:06:39 2013 Koichi Sasada <ko1@atdot.net>
* ext/objspace/object_tracing.c (newobj_i): fix memory leak.

View file

@ -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")

View file

@ -373,6 +373,7 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
if (PathIsRelativeW(whome) && !(whome_len >= 2 && IS_DIR_UNC_P(whome))) {
xfree(wpath);
xfree(whome);
rb_raise(rb_eArgError, "non-absolute home");
}
@ -441,6 +442,7 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
if (PathIsRelativeW(whome) && !(whome_len >= 2 && IS_DIR_UNC_P(whome))) {
xfree(wpath);
xfree(wdir);
xfree(whome);
rb_raise(rb_eArgError, "non-absolute home");
}