Commit 0355cfad authored by Niels Möller's avatar Niels Möller

Fix at-exit leak in eratosthenes program.

parent af7d1d76
2018-07-12 Niels Möller <nisse@lysator.liu.se>
* examples/eratosthenes.c (main): Don't allocate bitmap storage
for limit == 2 (early exit), closing memory leak at exit.
* eccdata.c (output_curve): Replace mpz_init_set_ui by mpz_set_ui,
to fix memory leak.
(ecc_curve_clear): New function.
......
......@@ -314,8 +314,6 @@ main (int argc, char **argv)
root = (root - 1) | 1;
/* Represents odd numbers from 3 up. */
sieve_nbits = (root - 1) / 2;
sieve = vector_alloc(sieve_nbits );
vector_init(sieve, sieve_nbits);
if (verbose)
fprintf(stderr, "Initial sieve using %lu bits.\n", sieve_nbits);
......@@ -326,6 +324,9 @@ main (int argc, char **argv)
if (limit == 2)
return EXIT_SUCCESS;
sieve = vector_alloc(sieve_nbits);
vector_init(sieve, sieve_nbits);
for (bit = 0;
bit < sieve_nbits;
bit = vector_find_next(sieve, bit + 1, sieve_nbits))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment