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

ruby-changes:34971

From: nagachika <ko1@a...>
Date: Mon, 4 Aug 2014 01:25:04 +0900 (JST)
Subject: [ruby-changes:34971] nagachika:r47053 (ruby_2_1): merge revision(s) r46550: [Backport #9977]

nagachika	2014-08-04 01:24:48 +0900 (Mon, 04 Aug 2014)

  New Revision: 47053

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

  Log:
    merge revision(s) r46550: [Backport #9977]
    
    * hash.c (ruby_setenv): fix memory leak on Windows, free
      environment strings block after check for the size.
      [ruby-dev:48323] [Bug #9977]

  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 47052)
+++ ruby_2_1/ChangeLog	(revision 47053)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Mon Aug  4 01:24:09 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* hash.c (ruby_setenv): fix memory leak on Windows, free
+	  environment strings block after check for the size.
+	  [ruby-dev:48323] [Bug #9977]
+
 Mon Aug  4 01:11:07 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* re.c (match_aref, rb_reg_regsub): consider encoding of captured
Index: ruby_2_1/hash.c
===================================================================
--- ruby_2_1/hash.c	(revision 47052)
+++ ruby_2_1/hash.c	(revision 47053)
@@ -2751,9 +2751,12 @@ ruby_setenv(const char *name, const char https://github.com/ruby/ruby/blob/trunk/ruby_2_1/hash.c#L2751
     int failed = 0;
     check_envname(name);
     if (value) {
-	const char* p = GetEnvironmentStringsA();
+	char* p = GetEnvironmentStringsA();
+	size_t n;
 	if (!p) goto fail; /* never happen */
-	if (strlen(name) + 2 + strlen(value) + getenvsize(p) >= getenvblocksize()) {
+	n = strlen(name) + 2 + strlen(value) + getenvsize(p);
+	FreeEnvironmentStringsA(p);
+	if (n >= getenvblocksize()) {
 	    goto fail;  /* 2 for '=' & '\0' */
 	}
 	buf = rb_sprintf("%s=%s", name, value);
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 47052)
+++ ruby_2_1/version.h	(revision 47053)
@@ -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 191
+#define RUBY_PATCHLEVEL 192
 
 #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 47052)
+++ ruby_2_1/test/ruby/test_env.rb	(revision 47053)
@@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_env.rb#L1
 require 'test/unit'
+require_relative 'envutil'
 
 class TestEnv < Test::Unit::TestCase
   IGNORE_CASE = /bccwin|mswin|mingw/ =~ RUBY_PLATFORM
@@ -408,4 +409,13 @@ class TestEnv < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_env.rb#L409
       keys.each {|k| ENV.delete(k)}
     end
   end
+
+  def test_memory_leak_aset
+    bug9977 = '[ruby-dev:48323] [Bug #9977]'
+    assert_no_memory_leak([], <<-'end;', "5_000.times {ENV[k] = v}", bug9977)
+      ENV.clear
+      k = 'FOO'
+      v = (ENV[k] = 'bar'*5000 rescue 'bar'*1500)
+    end;
+  end
 end

Property changes on: ruby_2_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r46550


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

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