From 46451d6e04c7fd384ae3846662cfb025c0ce6f43 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Fri, 19 Apr 2019 15:39:22 +0200 Subject: [PATCH] MINOR: gcc: Fix a silly gcc warning in connect_server() Don't know why it happens now, but gcc seems to think srv_conn may be NULL when a reused connection is removed from the orphan list. It happens when HAProxy is compiled with -O2 with my gcc (8.3.1) on fedora 29... Changing a little how reuse parameter is tested removes the warnings. So... This patch may be backported to 1.9. --- src/backend.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/backend.c b/src/backend.c index 40ce94987..d7695bf2c 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1374,18 +1374,21 @@ int connect_server(struct stream *s) /* If we're really reusing the connection, remove it from the orphan * list and add it back to the idle list. */ - if (reuse && reuse_orphan) { - srv_conn->idle_time = 0; - _HA_ATOMIC_SUB(&srv->curr_idle_conns, 1); - __ha_barrier_atomic_store(); - srv->curr_idle_thr[tid]--; - LIST_ADDQ(&srv->idle_conns[tid], &srv_conn->list); - } else if (reuse) { - if (srv_conn->flags & CO_FL_SESS_IDLE) { - struct session *sess = srv_conn->owner; - - srv_conn->flags &= ~CO_FL_SESS_IDLE; - sess->idle_conns--; + if (reuse) { + if (reuse_orphan) { + srv_conn->idle_time = 0; + _HA_ATOMIC_SUB(&srv->curr_idle_conns, 1); + __ha_barrier_atomic_store(); + srv->curr_idle_thr[tid]--; + LIST_ADDQ(&srv->idle_conns[tid], &srv_conn->list); + } + else { + if (srv_conn->flags & CO_FL_SESS_IDLE) { + struct session *sess = srv_conn->owner; + + srv_conn->flags &= ~CO_FL_SESS_IDLE; + sess->idle_conns--; + } } } -- 2.47.3