[前][次][番号順一覧][スレッド一覧]

ruby-changes:34972

From: nagachika <ko1@a...>
Date: Mon, 4 Aug 2014 01:28:39 +0900 (JST)
Subject: [ruby-changes:34972] nagachika:r47054 (ruby_2_1): merge revision(s) r46557, r46565: [Backport #9978]

nagachika	2014-08-04 01:28:20 +0900 (Mon, 04 Aug 2014)

  New Revision: 47054

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47054

  Log:
    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.

  Modified directories:
    branches/ruby_2_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/hash.c
    branches/ruby_2_1/test/ruby/test_env.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 47053)
+++ ruby_2_1/ChangeLog	(revision 47054)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Mon Aug  4 01:26:46 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* hash.c (env_select): fix memory leak and crash on Windows, make
+	  keys array first instead of iterating on environ directly.
+	  [ruby-dev:48325] [Bug #9978]
+
 Mon Aug  4 01:24:09 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* hash.c (ruby_setenv): fix memory leak on Windows, free
Index: ruby_2_1/hash.c
===================================================================
--- ruby_2_1/hash.c	(revision 47053)
+++ ruby_2_1/hash.c	(revision 47054)
@@ -3139,23 +3139,21 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_1/hash.c#L3139
 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;
 }
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 47053)
+++ ruby_2_1/version.h	(revision 47054)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.2"
 #define RUBY_RELEASE_DATE "2014-08-04"
-#define RUBY_PATCHLEVEL 192
+#define RUBY_PATCHLEVEL 193
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 8
Index: ruby_2_1/test/ruby/test_env.rb
===================================================================
--- ruby_2_1/test/ruby/test_env.rb	(revision 47053)
+++ ruby_2_1/test/ruby/test_env.rb	(revision 47054)
@@ -418,4 +418,20 @@ class TestEnv < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_env.rb#L418
       v = (ENV[k] = 'bar'*5000 rescue 'bar'*1500)
     end;
   end
+
+  def test_memory_leak_select
+    bug9978 = '[ruby-dev:48325] [Bug #9978]'
+    assert_no_memory_leak([], <<-'end;', "5_000.times {ENV.select {break}}", bug9978)
+      ENV.clear
+      k = 'FOO'
+      (ENV[k] = 'bar'*5000 rescue 'bar'*1500)
+    end;
+  end
+
+  def test_memory_crash_select
+    assert_normal_exit(<<-'end;')
+      1000.times {ENV["FOO#{i}"] = 'bar'}
+      ENV.select {ENV.clear}
+    end;
+  end
 end

Property changes on: ruby_2_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r46557,46565


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]