]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: backend: free allocated bind_addr if reuse conn
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 2 Mar 2021 11:01:06 +0000 (12:01 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 3 Mar 2021 10:28:02 +0000 (11:28 +0100)
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.

src/backend.c

index ef350f060024183c652da1f48ac2eac311d664b2..6d0fb8632ad3743e5d658298f01e7ba8f744c4a6 100644 (file)
@@ -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;