Skip to content

Commit e8df66a

Browse files
Darleletcapflam
authored andcommitted
BUG/MEDIUM: proxy: fix email-alert invalid free
In fa90a7d ("BUG/MINOR: proxy: fix email-alert leak on deinit()"), I tried to fix email-alert deinit() leak the simple way by leveraging existing free_email_alert() helper function which was already used for freeing email alert settings used in a default section. However, as described in GH #2608, there is a subtelty that makes free_email_alert() not suitable for use from free_proxy(). Indeed, proxy 'mailers.name' hint shares the same memory space than the pointer to the corresponding mailers section (once the proxy is resolved, name hint is replaced by the pointer to the section). However, since both values share the same space (through union), we have to take care of not freeing `mailers.name` once init_email_alert() was called on the proxy. Unfortunately, free_email_alert() isn't protected against that, causing double free() during deinit when mailers section is referenced from multiple proxy sections. Since there is no easy fix, and that the leak in itself isn't a big deal (fa90a7d was simply an opportunistic fix rather than a must-have given that the leak only occurs during deinit and not during runtime), let's actually revert the fix to restore legacy behavior and prevent deinit errors. Thanks to @snetAT for having reported the issue on Github as well as providing relevant infos to pinpoint the bug. It should be backported everywhere fa90a7d was backported. [ada: for versions prior to 3.0, simply revert the offending commit using 'git revert' as proxy_free_common() first appears in 3.0] (cherry picked from commit 8e22668) Signed-off-by: Christopher Faulet <[email protected]>
1 parent 98da556 commit e8df66a

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/proxy.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,6 @@ static inline void proxy_free_common(struct proxy *px)
253253
LIST_DEL_INIT(&lf->list);
254254

255255
chunk_destroy(&px->log_tag);
256-
257-
free_email_alert(px);
258256
}
259257

260258
void free_proxy(struct proxy *p)
@@ -1483,6 +1481,7 @@ void proxy_free_defaults(struct proxy *defproxy)
14831481

14841482
proxy_release_conf_errors(defproxy);
14851483
deinit_proxy_tcpcheck(defproxy);
1484+
free_email_alert(defproxy);
14861485

14871486
/* FIXME: we cannot free uri_auth because it might already be used by
14881487
* another proxy (legacy code for stats URI ...). Refcount anyone ?

0 commit comments

Comments
 (0)