* hash.c (env_shift): fix memory leak on Windows, free environment
  strings block always.  [ruby-dev:48332] [Bug #9983]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-06-26 20:33:34 +00:00
Родитель cfa7b2283b
Коммит 68bc5ba1b6
3 изменённых файлов: 17 добавлений и 2 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Fri Jun 27 05:33:26 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]
Fri Jun 27 03:41:53 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* sprintf.c (GETASTER): should not use the numbered argument to be

5
hash.c
Просмотреть файл

@ -3554,6 +3554,7 @@ static VALUE
env_shift(void)
{
char **env;
VALUE result = Qnil;
env = GET_ENVIRON(environ);
if (*env) {
@ -3562,11 +3563,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;
}
/*

Просмотреть файл

@ -533,4 +533,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