Skip to content

Commit

Permalink
plug memory leaks in mpf numeric functions
Browse files Browse the repository at this point in the history
  • Loading branch information
evaleev authored and loriab committed Oct 12, 2023
1 parent e7d0720 commit e39bdc2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions include/libint2/numeric.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e39bdc2

Please sign in to comment.