Make sure to correctly free memory on errors
This commit is contained in:
parent
1ca6ae7170
commit
044c611f50
1 changed files with 2 additions and 1 deletions
|
@ -26,12 +26,13 @@ int main(void) {
|
|||
int err = getline(&lineptr, &bufsize, stdin);
|
||||
if(err == -1) {
|
||||
fputs("Error reading line from user input\n", stderr);
|
||||
free(lineptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
uintmax_t user_input = abs(atoi(lineptr));
|
||||
free(lineptr);
|
||||
printf("\nRecursive factorial for number: %ju\n", factorial(user_input));
|
||||
printf("Iterative factorial for number: %ju\n", factorial_iter(user_input));
|
||||
free(lineptr);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue