From 2b5541d2c3cc133d08973173171ca30b6375f636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20A=2E=20Ortega?= Date: Sun, 12 Feb 2017 19:33:57 +0100 Subject: [PATCH] Fixed some memory leaks. --- src/files.c | 2 ++ src/list.c | 2 +- src/main.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/files.c b/src/files.c index f088657..d101830 100644 --- a/src/files.c +++ b/src/files.c @@ -15,6 +15,8 @@ int inputPrimes(char *file, List *list) { while(mpz_inp_raw(n, in)) if(addToList(list, n) == 1) return 3; + mpz_clear(n); + if(fclose(in)) return 2; return 0; } diff --git a/src/list.c b/src/list.c index 11482e9..391c4fe 100644 --- a/src/list.c +++ b/src/list.c @@ -15,7 +15,7 @@ int initList(List *restrict l) { } void deInitList(List *restrict l) { - for(size_t i = 0; i < l->size; ++i) { + for(size_t i = 0; i < l->end; ++i) { mpz_clear(l->list[i]); } free(l->list); diff --git a/src/main.c b/src/main.c index 6a5f5c8..c5dd96b 100644 --- a/src/main.c +++ b/src/main.c @@ -199,6 +199,7 @@ int main(int argc, char *argv[]) { while(mpz_cmp(primes.list[rootInd], numRoot) <= 0) { if(++rootInd > primes.end) { fprintf(stderr, "Error: `rootInd' surpassed `primes.end'.\n"); + exitCode = 1; goto releaseMemory; } }