Skip to content

Commit b57a859

Browse files
committed
merge revision(s) r46570: [Backport ruby#9983]
* hash.c (env_shift): fix memory leak on Windows, free environment strings block always. [ruby-dev:48332] [Bug ruby#9983] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@47055 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent f91bd16 commit b57a859

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Mon Aug 4 01:29:57 2014 Nobuyoshi Nakada <[email protected]>
2+
3+
* hash.c (env_shift): fix memory leak on Windows, free environment
4+
strings block always. [ruby-dev:48332] [Bug #9983]
5+
16
Mon Aug 4 01:26:46 2014 Nobuyoshi Nakada <[email protected]>
27

38
* hash.c (env_select): fix memory leak and crash on Windows, make

hash.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3557,6 +3557,7 @@ static VALUE
35573557
env_shift(void)
35583558
{
35593559
char **env;
3560+
VALUE result = Qnil;
35603561

35613562
env = GET_ENVIRON(environ);
35623563
if (*env) {
@@ -3565,11 +3566,11 @@ env_shift(void)
35653566
VALUE key = env_str_new(*env, s-*env);
35663567
VALUE val = env_str_new2(getenv(RSTRING_PTR(key)));
35673568
env_delete(Qnil, key);
3568-
return rb_assoc_new(key, val);
3569+
result = rb_assoc_new(key, val);
35693570
}
35703571
}
35713572
FREE_ENVIRON(environ);
3572-
return Qnil;
3573+
return result;
35733574
}
35743575

35753576
/*

test/ruby/test_env.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,4 +434,13 @@ def test_memory_crash_select
434434
ENV.select {ENV.clear}
435435
end;
436436
end
437+
438+
def test_memory_leak_shift
439+
bug9983 = '[ruby-dev:48332] [Bug #9983]'
440+
assert_no_memory_leak([], <<-'end;', "5_000.times {ENV.shift; ENV[k] = v}", bug9983)
441+
ENV.clear
442+
k = 'FOO'
443+
v = (ENV[k] = 'bar'*5000 rescue 'bar'*1500)
444+
end;
445+
end
437446
end

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.2"
22
#define RUBY_RELEASE_DATE "2014-08-04"
3-
#define RUBY_PATCHLEVEL 193
3+
#define RUBY_PATCHLEVEL 194
44

55
#define RUBY_RELEASE_YEAR 2014
66
#define RUBY_RELEASE_MONTH 8

0 commit comments

Comments
 (0)