diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | hash.c | 5 | ||||
-rw-r--r-- | test/ruby/test_env.rb | 9 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 18 insertions, 3 deletions
@@ -1,3 +1,8 @@ +Mon Aug 4 01:29:57 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * hash.c (env_shift): fix memory leak on Windows, free environment + strings block always. [ruby-dev:48332] [Bug #9983] + Mon Aug 4 01:26:46 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> * hash.c (env_select): fix memory leak and crash on Windows, make @@ -3557,6 +3557,7 @@ static VALUE env_shift(void) { char **env; + VALUE result = Qnil; env = GET_ENVIRON(environ); if (*env) { @@ -3565,11 +3566,11 @@ env_shift(void) VALUE key = env_str_new(*env, s-*env); VALUE val = env_str_new2(getenv(RSTRING_PTR(key))); env_delete(Qnil, key); - return rb_assoc_new(key, val); + result = rb_assoc_new(key, val); } } FREE_ENVIRON(environ); - return Qnil; + return result; } /* diff --git a/test/ruby/test_env.rb b/test/ruby/test_env.rb index 2b286de04e..2d0d7634fd 100644 --- a/test/ruby/test_env.rb +++ b/test/ruby/test_env.rb @@ -434,4 +434,13 @@ class TestEnv < Test::Unit::TestCase ENV.select {ENV.clear} end; end + + def test_memory_leak_shift + bug9983 = '[ruby-dev:48332] [Bug #9983]' + assert_no_memory_leak([], <<-'end;', "5_000.times {ENV.shift; ENV[k] = v}", bug9983) + ENV.clear + k = 'FOO' + v = (ENV[k] = 'bar'*5000 rescue 'bar'*1500) + end; + end end @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.1.2" #define RUBY_RELEASE_DATE "2014-08-04" -#define RUBY_PATCHLEVEL 193 +#define RUBY_PATCHLEVEL 194 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 8 |