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

ruby-changes:45773

From: naruse <ko1@a...>
Date: Sat, 11 Mar 2017 23:20:56 +0900 (JST)
Subject: [ruby-changes:45773] naruse:r57846 (ruby_2_4): merge revision(s) 57236: [Backport #13089]

naruse	2017-03-11 23:20:51 +0900 (Sat, 11 Mar 2017)

  New Revision: 57846

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

  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_4/
  Modified files:
    branches/ruby_2_4/rational.c
    branches/ruby_2_4/test/ruby/test_rational.rb
    branches/ruby_2_4/version.h
Index: ruby_2_4/rational.c
===================================================================
--- ruby_2_4/rational.c	(revision 57845)
+++ ruby_2_4/rational.c	(revision 57846)
@@ -261,10 +261,15 @@ rb_gcd_gmp(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/ruby_2_4/rational.c#L261
 
     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
Index: ruby_2_4/version.h
===================================================================
--- ruby_2_4/version.h	(revision 57845)
+++ ruby_2_4/version.h	(revision 57846)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1
 #define RUBY_VERSION "2.4.0"
 #define RUBY_RELEASE_DATE "2017-03-11"
-#define RUBY_PATCHLEVEL 13
+#define RUBY_PATCHLEVEL 14
 
 #define RUBY_RELEASE_YEAR 2017
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_4/test/ruby/test_rational.rb
===================================================================
--- ruby_2_4/test/ruby/test_rational.rb	(revision 57845)
+++ ruby_2_4/test/ruby/test_rational.rb	(revision 57846)
@@ -880,6 +880,16 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/ruby/test_rational.rb#L880
     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_predicate(1, :real?)
     assert_predicate(1.1, :real?)

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


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

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