From dd38b53e314b6024b6876e2d0788f3f3af25b696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20A=2E=20Ortega?= Date: Sat, 10 Dec 2016 11:20:01 +0100 Subject: [PATCH] Fixed leaks. --- src/list.c | 5 ++++- src/main.c | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/list.c b/src/list.c index 8801b02..51bfc48 100644 --- a/src/list.c +++ b/src/list.c @@ -21,6 +21,9 @@ void initList(List *l) { } void deInitList(List *l) { + for(ulli i = 0; i < l->size; ++i) { + mpz_clear(l->list[i]); + } free(l->list); } @@ -29,7 +32,7 @@ void addToList(List *l, mpz_t n) { l->size += BLOCK_SIZE; if(unlikely(l->size == 0)) { fprintf(stderr, - "size has reached limit of `long long int' type!\n"); + "Size has reached limit of `long long int' type!\n"); exit(1); } void *tmp = realloc(l->list, sizeof(mpz_t) * l->size); diff --git a/src/main.c b/src/main.c index ed056d0..60e5990 100644 --- a/src/main.c +++ b/src/main.c @@ -40,7 +40,8 @@ int main(void) { // Loop through found primes for(ulli i = 0; i < primes.size; ++i) { // If `num' is divisible by a prime then go to the next number - if(mpz_divisible_p(num, primes.list[i]) != 0) goto nextPrime; + if(mpz_divisible_p(num, primes.list[i]) != 0) + goto nextPrime; } // `num' is a prime so we add it to the list and print it @@ -56,6 +57,7 @@ nextPrime: mpz_add_ui(num, num, 2); } while(likely(run)); + mpz_clear(num); // Deinitialize the list deInitList(&primes); return 0;