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

ruby-changes:46018

From: usa <ko1@a...>
Date: Sun, 26 Mar 2017 00:19:12 +0900 (JST)
Subject: [ruby-changes:46018] usa:r58089 (ruby_2_2): merge revision(s) 57236: [Backport #13089]

usa	2017-03-26 00:19:09 +0900 (Sun, 26 Mar 2017)

  New Revision: 58089

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

  Log:
    merge revision(s) 57236: [Backport #13089]
    
    rational.c: memory leak in gcd
    
    * rational.c (rb_gcd_gmp): fix memory leak.  patched by KISHIMOTO,
      Makoto <ksmakoto AT dd.iij4u.or.jp> in [ruby-dev:49934].
      [Bug #13089]

  Modified directories:
    branches/ruby_2_2/
  Modified files:
    branches/ruby_2_2/rational.c
    branches/ruby_2_2/test/ruby/test_rational.rb
    branches/ruby_2_2/version.h
Index: ruby_2_2/version.h
===================================================================
--- ruby_2_2/version.h	(revision 58088)
+++ ruby_2_2/version.h	(revision 58089)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1
 #define RUBY_VERSION "2.2.7"
 #define RUBY_RELEASE_DATE "2017-03-26"
-#define RUBY_PATCHLEVEL 421
+#define RUBY_PATCHLEVEL 422
 
 #define RUBY_RELEASE_YEAR 2017
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_2/test/ruby/test_rational.rb
===================================================================
--- ruby_2_2/test/ruby/test_rational.rb	(revision 58088)
+++ ruby_2_2/test/ruby/test_rational.rb	(revision 58089)
@@ -864,6 +864,16 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_rational.rb#L864
     assert_equal(1152921470247108503, 1073741789.lcm(1073741827))
   end
 
+  def test_gcd_no_memory_leak
+    assert_no_memory_leak([], "#{<<-"begin;"}", "#{<<-"end;"}", limit: 1.2, rss: true)
+    x = (1<<121) + 1
+    y = (1<<99) + 1
+    1000.times{x.gcd(y)}
+    begin;
+      100.times {1000.times{x.gcd(y)}}
+    end;
+  end
+
   def test_supp
     assert_equal(true, 1.real?)
     assert_equal(true, 1.1.real?)
Index: ruby_2_2/rational.c
===================================================================
--- ruby_2_2/rational.c	(revision 58088)
+++ ruby_2_2/rational.c	(revision 58089)
@@ -286,10 +286,15 @@ rb_gcd_gmp(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/rational.c#L286
 
     mpz_gcd(mz, mx, my);
 
+    mpz_clear(mx);
+    mpz_clear(my);
+
     zn = (mpz_sizeinbase(mz, 16) + SIZEOF_BDIGIT*2 - 1) / (SIZEOF_BDIGIT*2);
     z = rb_big_new(zn, 1);
     mpz_export(BIGNUM_DIGITS(z), &count, -1, sizeof(BDIGIT), 0, nails, mz);
 
+    mpz_clear(mz);
+
     return rb_big_norm(z);
 }
 #endif

Property changes on: ruby_2_2
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r57236


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

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