diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2007-07-03 16:11:39 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2007-07-03 16:11:39 +0000 |
commit | 6affaf1441bd7f7839bc043437bc042bd2ce28e2 (patch) | |
tree | bb5a19b3b8db7e8edd18a139557666e18b3c793c | |
parent | ea53a94d771b99a9ec38818f1565e058748b0df7 (diff) | |
download | mpfr-6affaf1441bd7f7839bc043437bc042bd2ce28e2.tar.gz |
Fixed the bug reported by David Billinghurst to the MPFR mailing-list
on 2007-07-03 (memory leaks under some conditions):
* moved the free_l2b() function from tests/tests.c to free_cache.c;
* mpfr_free_cache() (from free_cache.c) now calls free_l2b();
* as a consequence, no longer call free_l2b() in tests_end_mpfr();
* documented the behavior in mpfr.texi (under mpfr_free_cache).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@4622 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | free_cache.c | 18 | ||||
-rw-r--r-- | mpfr.texi | 5 | ||||
-rw-r--r-- | tests/tests.c | 18 |
3 files changed, 21 insertions, 20 deletions
diff --git a/free_cache.c b/free_cache.c index 1b9c8379e..8d207ffcb 100644 --- a/free_cache.c +++ b/free_cache.c @@ -22,6 +22,23 @@ MA 02110-1301, USA. */ #include "mpfr-impl.h" +static void +free_l2b (void) +{ + int i, b; + + for (b = 2; b <= BASE_MAX; b++) + for (i = 0; i < 2; i++) + { + mpfr_ptr p = mpfr_l2b[b-2][i]; + if (p != NULL) + { + mpfr_clear (p); + (*__gmp_free_func) (p, sizeof (mpfr_t)); + } + } +} + void mpfr_free_cache (void) { @@ -29,4 +46,5 @@ mpfr_free_cache (void) mpfr_clear_cache (__gmpfr_cache_const_log2); mpfr_clear_cache (__gmpfr_cache_const_euler); mpfr_clear_cache (__gmpfr_cache_const_catalan); + free_l2b (); } @@ -1634,10 +1634,11 @@ use @code{mpfr_free_cache}. @end deftypefun @deftypefun void mpfr_free_cache (void) -Free the cache used by the functions computing constants if needed -(currently +Free various caches used by MPFR internally, in particular the +caches used by the functions computing constants (currently @code{mpfr_const_log2}, @code{mpfr_const_pi}, @code{mpfr_const_euler} and @code{mpfr_const_catalan}). +You should call this function when terminating a thread. @end deftypefun @deftypefun int mpfr_sum (mpfr_t @var{rop}, mpfr_ptr const @var{tab}[], unsigned long @var{n}, mp_rnd_t @var{rnd}) diff --git a/tests/tests.c b/tests/tests.c index 5da3988ff..bdf8709cd 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -96,23 +96,6 @@ extern void (*dummy_func) (mpfr_srcptr); void (*dummy_func)(mpfr_srcptr) = mpfr_dump; #endif -static void -free_l2b (void) -{ - int i, b; - - for (b = 2; b <= BASE_MAX; b++) - for (i = 0; i < 2; i++) - { - mpfr_ptr p = mpfr_l2b[b-2][i]; - if (p != NULL) - { - mpfr_clear (p); - (*__gmp_free_func) (p, sizeof (mpfr_t)); - } - } -} - void tests_start_mpfr (void) { @@ -138,7 +121,6 @@ tests_start_mpfr (void) void tests_end_mpfr (void) { - free_l2b (); mpfr_free_cache (); tests_rand_end (); tests_memory_end (); |