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

ruby-changes:34489

From: nobu <ko1@a...>
Date: Fri, 27 Jun 2014 05:33:51 +0900 (JST)
Subject: [ruby-changes:34489] nobu:r46570 (trunk): hash.c: fix memory leak

nobu	2014-06-27 05:33:34 +0900 (Fri, 27 Jun 2014)

  New Revision: 46570

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

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

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
    trunk/test/ruby/test_env.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46569)
+++ ChangeLog	(revision 46570)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jun 27 05:33:26 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* sprintf.c (GETASTER): should not use the numbered argument to be
Index: hash.c
===================================================================
--- hash.c	(revision 46569)
+++ hash.c	(revision 46570)
@@ -3554,6 +3554,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/hash.c#L3554
 env_shift(void)
 {
     char **env;
+    VALUE result = Qnil;
 
     env = GET_ENVIRON(environ);
     if (*env) {
@@ -3562,11 +3563,11 @@ env_shift(void) https://github.com/ruby/ruby/blob/trunk/hash.c#L3563
 	    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;
 }
 
 /*
Index: test/ruby/test_env.rb
===================================================================
--- test/ruby/test_env.rb	(revision 46569)
+++ test/ruby/test_env.rb	(revision 46570)
@@ -533,4 +533,13 @@ class TestEnv < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_env.rb#L533
       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

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

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