From: Amaury Denoyelle Date: Tue, 2 Mar 2021 11:01:06 +0000 (+0100) Subject: BUG/MINOR: backend: free allocated bind_addr if reuse conn X-Git-Tag: v2.4-dev11~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=68967e595b4bcd4aaab998fcf96f1e1aeb2b68a5;p=thirdparty%2Fhaproxy.git BUG/MINOR: backend: free allocated bind_addr if reuse conn Fix a leak in connect_server which happens when a connection is reused and a bind_addr was allocated because transparent mode is active. The connection has already an allocated bind_addr so free the newly allocated one. No backport needed. --- diff --git a/src/backend.c b/src/backend.c index ef350f0600..6d0fb8632a 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1506,19 +1506,24 @@ skip_reuse: if (reuse_mode == PR_O_REUSE_NEVR) conn_set_private(srv_conn); + /* assign bind_addr to srv_conn */ srv_conn->src = bind_addr; + bind_addr = NULL; if (!sockaddr_alloc(&srv_conn->dst, 0, 0)) { conn_free(srv_conn); return SF_ERR_RESOURCE; } } - else { - sockaddr_free(&bind_addr); - return SF_ERR_RESOURCE; - } } + /* if bind_addr is non NULL free it */ + sockaddr_free(&bind_addr); + + /* srv_conn is still NULL only on allocation failure */ + if (!srv_conn) + return SF_ERR_RESOURCE; + /* copy the target address into the connection */ *srv_conn->dst = *s->target_addr;