[MEDIUM] Fix memory freeing at exit, part 2
- free oldpids
- call free(exp->preg), not only regfree(exp->preg): req_exp, rsp_exp
- build a list of unique uri_auths and eventually free it
- prune_acl_cond/free for switching_rules
- add a callback pointer to free ptr from acl_pattern (used for regexs) and execute it
==1180== malloc/free: in use at exit: 0 bytes in 0 blocks.
==1180== malloc/free: 5,599 allocs, 5,599 frees, 4,220,556 bytes allocated.
==1180== All heap blocks were freed -- no leaks are possible.
diff --git a/src/acl.c b/src/acl.c
index 96b21de..02678f2 100644
--- a/src/acl.c
+++ b/src/acl.c
@@ -285,6 +285,12 @@
return 1;
}
+/* Free data allocated by acl_parse_reg */
+static void acl_free_reg(void *ptr) {
+
+ regfree((regex_t *)ptr);
+}
+
/* Parse a regex. It is allocated. */
int acl_parse_reg(const char **text, struct acl_pattern *pattern, int *opaque)
{
@@ -303,6 +309,7 @@
}
pattern->ptr.reg = preg;
+ pattern->freeptrbuf = &acl_free_reg;
return 1;
}
@@ -452,8 +459,14 @@
static void free_pattern(struct acl_pattern *pat)
{
- if (pat->ptr.ptr)
+
+ if (pat->ptr.ptr) {
+ if (pat->freeptrbuf)
+ pat->freeptrbuf(pat->ptr.ptr);
+
free(pat->ptr.ptr);
+ }
+
free(pat);
}