Fixed leaks.
This commit is contained in:
parent
3c8b9922fb
commit
dd38b53e31
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user