summaryrefslogtreecommitdiff
path: root/src/cosu.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2021-01-14 09:33:30 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2021-01-14 09:33:30 +0000
commit632660dfc7af2c5018d423d5cf7abc1f491dfcba (patch)
tree2e4c2f1e2fb87f1a44cce1ee76cf9c64e5c1f5d9 /src/cosu.c
parente84db2bf2b411cf26e403f81f99cfc6345abc322 (diff)
downloadmpfr-632660dfc7af2c5018d423d5cf7abc1f491dfcba.tar.gz
[src/cosu.c] Fixed memory leak with very small reduced arguments.
git-svn-id: https://scm.gforge.inria.fr/anonscm/svn/mpfr/trunk@14253 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/cosu.c')
-rw-r--r--src/cosu.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/cosu.c b/src/cosu.c
index 5ce504cc5..f9b4af932 100644
--- a/src/cosu.c
+++ b/src/cosu.c
@@ -75,6 +75,15 @@ mpfr_cosu (mpfr_ptr y, mpfr_srcptr x, unsigned long u, mpfr_rnd_t rnd_mode)
xp = xr;
}
+#define CLEAR_XR \
+ do \
+ if (xp != x) \
+ { \
+ MPFR_ASSERTD (xp == xr); \
+ mpfr_clear (xr); \
+ } \
+ while (0)
+
/* now |xp/u| < 1 */
/* for x small, we have |cos(2*pi*x/u)-1| < 1/2*(2*pi*x/u)^2 < 2^5*(x/u)^2 */
@@ -95,7 +104,7 @@ mpfr_cosu (mpfr_ptr y, mpfr_srcptr x, unsigned long u, mpfr_rnd_t rnd_mode)
mpfr_exp_t err1 = errb >= 0 || erra < MPFR_EXP_MAX + errb ?
erra - errb : MPFR_EXP_MAX;
MPFR_SMALL_INPUT_AFTER_SAVE_EXPO (y, __gmpfr_one, err1, 0, 0,
- rnd_mode, expo, {});
+ rnd_mode, expo, CLEAR_XR);
}
precy = MPFR_GET_PREC (y);
@@ -217,11 +226,7 @@ mpfr_cosu (mpfr_ptr y, mpfr_srcptr x, unsigned long u, mpfr_rnd_t rnd_mode)
end:
mpfr_clear (t);
- if (xp != x)
- {
- MPFR_ASSERTD (xp == xr);
- mpfr_clear (xr);
- }
+ CLEAR_XR;
MPFR_SAVE_EXPO_FREE (expo);
return underflow ? inexact : mpfr_check_range (y, inexact, rnd_mode);
}