Skip to content

Commit

Permalink
Trap memory failures
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Dec 27, 2024
1 parent 7ff1870 commit 00cea44
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sniff2ban.c
Original file line number Diff line number Diff line change
Expand Up @@ -2548,9 +2548,9 @@ setup_apache_hosts(void)
tail = tail->next;
}
if(tail == NULL)
fputs("Memory allocation failure\n", stderr);
fclose(fin);
closedir(dirp);
fputs("Memory allocation failure\n", stderr);
return;
}

Expand All @@ -2560,6 +2560,13 @@ setup_apache_hosts(void)
if(verbose >= 3)
printf("Adding apache hostname %s\n", p);
tail->name = strdup(p);
if(tail->name == NULL) {
free(tail);
fclose(fin);
closedir(dirp);
fputs("Memory allocation failure\n", stderr);
return;
}
tail->next = NULL;
}
fclose(fin);
Expand Down

0 comments on commit 00cea44

Please sign in to comment.