BUG/MINOR: mailers: Fix a memory leak when email alerts are released
An email alert contains a list of tcpcheck_rule. Each one is dynamically
allocated, just like its internal members. So, when an email alerts is freed, we
must be sure to properly free each tcpcheck_rule too.
This patch must be backported in 1.7 and 1.6.
diff --git a/src/checks.c b/src/checks.c
index ed9a49a..d9c3393 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -3038,8 +3038,14 @@
if (!alert)
return;
- list_for_each_entry_safe(rule, back, &alert->tcpcheck_rules, list)
+ list_for_each_entry_safe(rule, back, &alert->tcpcheck_rules, list) {
+ LIST_DEL(&rule->list);
+ free(rule->comment);
+ free(rule->string);
+ if (rule->expect_regex)
+ regex_free(rule->expect_regex);
free(rule);
+ }
free(alert);
}