From 6adc75887dddba9d694d14f40e16421d7f8b7fb7 Mon Sep 17 00:00:00 2001 From: RainRat Date: Thu, 30 Nov 2023 16:15:03 -0800 Subject: [PATCH] Fix possible memory leak if memory reallocation fails 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: https://github.com/Cisco-Talos/clamav/issues/1092 --- clamav-milter/allow_list.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/clamav-milter/allow_list.c b/clamav-milter/allow_list.c index 09f37ff560..50f9ed2bd0 100644 --- a/clamav-milter/allow_list.c +++ b/clamav-milter/allow_list.c @@ -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) {