diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-08-03 16:28:20 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-08-03 16:28:20 +0000 |
commit | 85c48fdc312a923c1bfe0ed88fa302d6417d9402 (patch) | |
tree | a3c657cd2f7d609552fe78d0f3052f41ec4dd651 /hash.c | |
parent | d4132b8ae0e79f3fc21bad0fdba1a79fdd6c48b0 (diff) |
merge revision(s) r46557,r46565: [Backport #9978]
* hash.c (env_select): fix memory leak and crash on Windows, make
keys array first instead of iterating on envrion directly.
[ruby-dev:48325] [Bug #9978]
keys array first instead of iterating on environ directly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@47054 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 20 |
1 files changed, 9 insertions, 11 deletions
@@ -3139,23 +3139,21 @@ static VALUE env_select(VALUE ehash) { VALUE result; - char **env; + VALUE keys; + long i; RETURN_SIZED_ENUMERATOR(ehash, 0, 0, rb_env_size); result = rb_hash_new(); - env = GET_ENVIRON(environ); - while (*env) { - char *s = strchr(*env, '='); - if (s) { - VALUE k = env_str_new(*env, s-*env); - VALUE v = env_str_new2(s+1); - if (RTEST(rb_yield_values(2, k, v))) { - rb_hash_aset(result, k, v); + keys = env_keys(); + for (i = 0; i < RARRAY_LEN(keys); ++i) { + VALUE key = RARRAY_AREF(keys, i); + VALUE val = rb_f_getenv(Qnil, key); + if (!NIL_P(val)) { + if (RTEST(rb_yield_values(2, key, val))) { + rb_hash_aset(result, key, val); } } - env++; } - FREE_ENVIRON(environ); return result; } |