summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-17 17:09:07 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-17 17:09:07 +0000
commit4c9a4c333102faf6b905e26300151c81780411a2 (patch)
treedf65774e8ca39e90fcab4384ae320dcbe850841b
parentf0aa371165d23f9681450a0d70e3ddf8c26a06c5 (diff)
merge revision(s) 43328: [Backport #9033]
* 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/branches/ruby_2_0_0@43344 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--test/ruby/test_file_exhaustive.rb27
-rw-r--r--version.h6
-rw-r--r--win32/file.c2
4 files changed, 37 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index cb9e93121c..86f46a2834 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Oct 18 02:05:45 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 10 01:14:37 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* compar.c (cmp_eq): fail if recursion. [ruby-core:57736] [Bug #9003]
diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb
index 8a33258759..beeab8dc29 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")
diff --git a/version.h b/version.h
index 519364941e..cbd6b3cecb 100644
--- a/version.h
+++ b/version.h
@@ -1,10 +1,10 @@
#define RUBY_VERSION "2.0.0"
-#define RUBY_RELEASE_DATE "2013-10-11"
-#define RUBY_PATCHLEVEL 335
+#define RUBY_RELEASE_DATE "2013-10-18"
+#define RUBY_PATCHLEVEL 336
#define RUBY_RELEASE_YEAR 2013
#define RUBY_RELEASE_MONTH 10
-#define RUBY_RELEASE_DAY 11
+#define RUBY_RELEASE_DAY 18
#include "ruby/version.h"
diff --git a/win32/file.c b/win32/file.c
index 96fe61bad2..f20dedf06d 100644
--- a/win32/file.c
+++ b/win32/file.c
@@ -405,6 +405,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");
}
@@ -470,6 +471,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");
}