summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-07 14:42:52 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-07 14:42:52 +0000
commit1be6a498ba8d1c113d4e0e7547d01c86c188e5c4 (patch)
tree34d65cf35842ad8a4c851fee2e52a8f109625314 /ext/bigdecimal
parent19768b6cacb1319f34944a0dc5e0bbe099d2d18e (diff)
* ext/bigdecimal/bigdecimal.c (rmpd_power_by_big_decimal):
add RB_GC_GUARD to prevent the immediate object is GCed too early. This patch was made by Yusuke Endoh. [Bug #7044] [ruby-core:47632] * test/bigdecimal/test_bigdecimal.rb: add a reproduction test for the issue [Bug #7044] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index b161bc95ca..7cd0044532 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -2046,6 +2046,7 @@ static VALUE
rmpd_power_by_big_decimal(Real const* x, Real const* exp, ssize_t const n)
{
VALUE log_x, multiplied, y;
+ volatile VALUE obj = exp->obj;
if (VpIsZero(exp)) {
return ToValue(VpCreateRbObject(n, "1"));
@@ -2054,6 +2055,7 @@ rmpd_power_by_big_decimal(Real const* x, Real const* exp, ssize_t const n)
log_x = BigMath_log(x->obj, SSIZET2NUM(n+1));
multiplied = BigDecimal_mult2(exp->obj, log_x, SSIZET2NUM(n+1));
y = BigMath_exp(multiplied, SSIZET2NUM(n));
+ RB_GC_GUARD(obj);
return y;
}