From e39bdc20b30d4246e6e77f285421314a1ee26d9b Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Mon, 5 Jul 2021 21:10:25 -0400 Subject: [PATCH] plug memory leaks in mpf numeric functions --- include/libint2/numeric.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/libint2/numeric.h b/include/libint2/numeric.h index 478acf88e..1d68ea18f 100644 --- a/include/libint2/numeric.h +++ b/include/libint2/numeric.h @@ -34,6 +34,11 @@ mpf_init2(expx, prec); mpfr_get_f(expx, expx_r, MPFR_RNDN); mpf_class result(expx, prec); + + mpfr_clear(x_r); + mpfr_clear(expx_r); + mpf_clear(expx); + return result; } /// implement pow for mpf_class using MPFR ... I do not claim to know what issues the rounding presents here @@ -48,6 +53,7 @@ mpf_class result(x_to_a, prec); if (a < 0) result = 1.0 / result; + mpf_clear(x_to_a); return result; } /// this is needed to avoid ambiguity in pow(2.0, 2) ... the above pow competes with standard double pow(double, double) @@ -67,6 +73,11 @@ mpf_init2(erfx, prec); mpfr_get_f(erfx, erfx_r, MPFR_RNDN); mpf_class result(erfx, prec); + + mpfr_clear(x_r); + mpfr_clear(erfx_r); + mpf_clear(erfx); + return result; } /// implement acos for mpf_class using MPFR ... I do not claim to know what issues the rounding presents here @@ -82,6 +93,11 @@ mpf_init2(acosx, prec); mpfr_get_f(acosx, acosx_r, MPFR_RNDN); mpf_class result(acosx, prec); + + mpfr_clear(x_r); + mpfr_clear(acosx_r); + mpf_clear(acosx); + return result; } /// implement log for mpf_class using MPFR ... I do not claim to know what issues the rounding presents here @@ -97,6 +113,11 @@ mpf_init2(logx, prec); mpfr_get_f(logx, logx_r, MPFR_RNDN); mpf_class result(logx, prec); + + mpfr_clear(x_r); + mpfr_clear(logx_r); + mpf_clear(logx); + return result; } #endif