X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/e039785ff339715241e3db891b9dddc9e201768e..3d86dc1eec364744b12daf0230d072a4317d78bc:/math/limlee.c diff --git a/math/limlee.c b/math/limlee.c index 28975d0c..c99ba7bd 100644 --- a/math/limlee.c +++ b/math/limlee.c @@ -390,6 +390,8 @@ mp *limlee(const char *name, mp *d, mp *newp, { limlee_stepctx l; rabin rr; + mp **v; + size_t i; l.f = 0; if (f) l.f |= LIMLEE_KEEPFACTORS; l.newp = newp; @@ -402,15 +404,18 @@ mp *limlee(const char *name, mp *d, mp *newp, d = pgen(name, d, 0, oev, oec, on, limlee_step, &l, rabin_iters(pl), pgen_test, &rr); - if (d && f) { - mp **v; - size_t i; - v = xmalloc(l.nf * sizeof(mp *)); - for (i = 0; i < l.nf; i++) - v[i] = l.v[i].p; - xfree(l.v); - *f = v; - *nf = l.nf; + if (f) { + if (!d) { + for (i = 0; i < l.nf; i++) + if (l.v[i].p) llfree(&l.v[i], &l); + } else { + v = xmalloc(l.nf * sizeof(mp *)); + for (i = 0; i < l.nf; i++) + v[i] = l.v[i].p; + xfree(l.v); + *f = v; + *nf = l.nf; + } } return (d);