memory leak huge number of digits mpz_mul,mpf_sqrt_ui
Paul Zimmermann
Paul.Zimmermann at inria.fr
Fri Feb 26 08:03:51 UTC 2021
Dear Susumu tsukamoto,
I tried valgrind with the following simplified program and it shows no memory
leak:
$ cat test_mul.c
#include "gmp.h"
int main()
{
long int num = 200000; // 200,000,000
long int ik;
mpz_t DC;
printf(" start: num= %'ld \n", num);
mpz_init_set_str(DC, "10000000000000000000",10); // DC=10^19
ik = 19; // DC=10^ik set num/2 <= ik < num
while (ik * 2 < num) {
mpz_mul(DC, DC, DC);
ik = ik * 2;
}
mpz_clear(DC);
}
$ /usr/bin/g++ -g -Wall test_mul.c -o test_mul01 -lgmp
$ valgrind ./test_mul01
...
==23406== HEAP SUMMARY:
==23406== in use at exit: 0 bytes in 0 blocks
==23406== total heap usage: 17 allocs, 17 frees, 231,296 bytes allocated
==23406==
==23406== All heap blocks were freed -- no leaks are possible
Does valgrind report a memory leak with your original value num=200000000?
Best regards,
Paul Zimmermann
More information about the gmp-bugs
mailing list