Fixed some memory leaks.

This commit is contained in:
Nicolás A. Ortega 2017-02-12 19:33:57 +01:00
parent 94248612ba
commit 2b5541d2c3
No known key found for this signature in database
GPG Key ID: 614272579C2070D1
3 changed files with 4 additions and 1 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}
}