summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-25 15:19:09 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-25 15:19:09 +0000
commitd53acd8540e7370cc852222e7e53cb8e904d0cc3 (patch)
treefa0bc74f67ad7d3cd23f89ca7d183084f1b13450
parentc74055003d07147c4d917e60b0e61874effa5abb (diff)
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@58089 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--rational.c5
-rw-r--r--test/ruby/test_rational.rb10
-rw-r--r--version.h2
3 files changed, 16 insertions, 1 deletions
diff --git a/rational.c b/rational.c
index 134db642c1..8fa69bd114 100644
--- a/rational.c
+++ b/rational.c
@@ -286,10 +286,15 @@ rb_gcd_gmp(VALUE x, VALUE y)
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
diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb
index ae4a2c6dd6..44f7280071 100644
--- a/test/ruby/test_rational.rb
+++ b/test/ruby/test_rational.rb
@@ -864,6 +864,16 @@ class Rational_Test < Test::Unit::TestCase
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?)
diff --git a/version.h b/version.h
index f551e9b93e..495bbfc08e 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#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