Skip to content

Commit

Permalink
Fix possible memory leak if memory reallocation fails
Browse files Browse the repository at this point in the history
In clamav-milter's `allow_list.c` `cli_regex2suffix`, if the realloc
fails it's possible the original memory may not be free'd. 

Fixes: #1092
  • Loading branch information
RainRat authored Dec 1, 2023
1 parent dbc6ffe commit 6adc758
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions clamav-milter/allow_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ int smtpauth_init(const char *r)
}
if (len <= 0) continue;
if (len * 3 + 1 > rxavail) {
ptr = regex;
regex = realloc(regex, rxsize + 2048);
if (!regex) {
ptr = regex;
char *temp = realloc(regex, rxsize + 2048);
if (!temp) {
free(regex);
logg(LOGG_ERROR, "Cannot allocate memory for SkipAuthenticated file\n");
fclose(f);
return 1;
}
regex = temp;
rxavail = 2048;
rxsize += 2048;
if (!ptr) {
Expand Down

0 comments on commit 6adc758

Please sign in to comment.