GMP memory leakage global variable

Marco Bodrato bodrato at mail.dm.unipi.it
Mon Jul 5 18:18:43 UTC 2021


Ciao,

Il Lun, 5 Luglio 2021 12:41 am, chmol10 at wp.pl ha scritto:
> Hi,     I have a problem with variable l. The during the do-while loop
> execution, variable l is still in use and memory is leaking. The loop is

Variable l is used, and its memory use will (very slowly, if I understand
the program) grow. That's normal if you keep a variable alive and it has
to store growing numbers.

> endlessly executing. How to repair this leakage? Here is the main part of
> the code:   mpz_t l;

Not enough. I agree with Pedro Gimeno. There isn't any detectable leek on l.

But...

> gmp_scanf("%Zd", (value);

Be careful! You are using value without initialising it!
This is "Undefined Behaviour"!
Thanks to lazy-allocation, maybe your program doesn't crash and work as if
value was init'ed to zero...

> mpz_init_set_si(value, 100000000000000000);

...but then you (re-)init value... without cleaning it!
This gives a leak, for sure :-)

>                analyze(n);

I'd suggest to look inside that black-box, maybe there are some other not
correctly initialised, doubly initialised, not cleaned variables...

Ĝis,
m



More information about the gmp-discuss mailing list