danaj / Math-Prime-Util

Perl (XS) module implementing prime number utilities, including sieves

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory leak in forsquarefree

trizen opened this issue · comments

It seems that there are some memory leaks in forsquarefree every time the function is called.

The issue can be reproduced with the code below, which starts using more and more RAM.

use ntheory qw(:all);

for (my $n = 1; ; $n += 1e6) {
    forsquarefree {
        # ...
    } $n, $n+1e6;
}

This also seems to happen with the forfactored loop.

Other loops, such as forprimes or forcomposites, do not have this issue.

forsquarefree and forfactored were missing a factor_range_destroy call. Added, with many thanks!

Thank you for the fix. Welcome back! :)