]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: muxes: Don't expect to call release function with no mux defined
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 14 Apr 2022 09:36:41 +0000 (11:36 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 14 Apr 2022 09:57:06 +0000 (11:57 +0200)
For all muxes, the function responsible to release a mux is always called
with a defined mux. Thus there is no reason to test if it is defined or not.

Note the patch may seem huge but it is just because of indentation changes.

src/mux_fcgi.c
src/mux_h1.c
src/mux_h2.c
src/mux_pt.c
src/mux_quic.c

index cfe39dd83330d69cc59bdd63312e6020fbcdec9e..b6ca2dba7c4930f86422a98c5d763f8bbef304a8 100644 (file)
@@ -840,34 +840,28 @@ static inline struct fcgi_strm *fcgi_conn_st_by_id(struct fcgi_conn *fconn, int
  */
 static void fcgi_release(struct fcgi_conn *fconn)
 {
-       struct connection *conn = NULL;
+       struct connection *conn = fconn->conn;
 
        TRACE_POINT(FCGI_EV_FCONN_END);
 
-       if (fconn) {
-               conn = fconn->conn;
-
-               TRACE_DEVEL("freeing fconn", FCGI_EV_FCONN_END, conn);
-
-               if (LIST_INLIST(&fconn->buf_wait.list))
-                       LIST_DEL_INIT(&fconn->buf_wait.list);
-
-               fcgi_release_buf(fconn, &fconn->dbuf);
-               fcgi_release_mbuf(fconn);
+       if (LIST_INLIST(&fconn->buf_wait.list))
+               LIST_DEL_INIT(&fconn->buf_wait.list);
 
-               if (fconn->task) {
-                       fconn->task->context = NULL;
-                       task_wakeup(fconn->task, TASK_WOKEN_OTHER);
-                       fconn->task = NULL;
-               }
-               if (fconn->wait_event.tasklet)
-                       tasklet_free(fconn->wait_event.tasklet);
-               if (conn && fconn->wait_event.events != 0)
-                       conn->xprt->unsubscribe(conn, conn->xprt_ctx, fconn->wait_event.events,
-                                               &fconn->wait_event);
+       fcgi_release_buf(fconn, &fconn->dbuf);
+       fcgi_release_mbuf(fconn);
 
-               pool_free(pool_head_fcgi_conn, fconn);
+       if (fconn->task) {
+               fconn->task->context = NULL;
+               task_wakeup(fconn->task, TASK_WOKEN_OTHER);
+               fconn->task = NULL;
        }
+       if (fconn->wait_event.tasklet)
+               tasklet_free(fconn->wait_event.tasklet);
+       if (conn && fconn->wait_event.events != 0)
+               conn->xprt->unsubscribe(conn, conn->xprt_ctx, fconn->wait_event.events,
+                                       &fconn->wait_event);
+
+       pool_free(pool_head_fcgi_conn, fconn);
 
        if (conn) {
                conn->mux = NULL;
index fb4cd28f420733fc707a94837eba397f81adee16..cd5f3fb7370d9bff49d5c637170587875f2ffa74 100644 (file)
@@ -1055,56 +1055,52 @@ static void h1_release(struct h1c *h1c)
 
        TRACE_POINT(H1_EV_H1C_END);
 
-       if (h1c) {
-               /* The connection must be aattached to this mux to be released */
-               if (h1c->conn && h1c->conn->ctx == h1c)
-                       conn = h1c->conn;
-
-               TRACE_DEVEL("freeing h1c", H1_EV_H1C_END, conn);
-
-               if (conn && h1c->flags & H1C_F_UPG_H2C) {
-                       TRACE_DEVEL("upgrading H1 to H2", H1_EV_H1C_END, conn);
-                       /* Make sure we're no longer subscribed to anything */
-                       if (h1c->wait_event.events)
-                               conn->xprt->unsubscribe(conn, conn->xprt_ctx,
-                                   h1c->wait_event.events, &h1c->wait_event);
-                       if (conn_upgrade_mux_fe(conn, NULL, &h1c->ibuf, ist("h2"), PROTO_MODE_HTTP) != -1) {
-                               /* connection successfully upgraded to H2, this
-                                * mux was already released */
-                               return;
-                       }
-                       TRACE_ERROR("h2 upgrade failed", H1_EV_H1C_END|H1_EV_H1C_ERR, conn);
-                       sess_log(conn->owner); /* Log if the upgrade failed */
-               }
+       /* The connection must be aattached to this mux to be released */
+       if (h1c->conn && h1c->conn->ctx == h1c)
+               conn = h1c->conn;
 
+       if (conn && h1c->flags & H1C_F_UPG_H2C) {
+               TRACE_DEVEL("upgrading H1 to H2", H1_EV_H1C_END, conn);
+               /* Make sure we're no longer subscribed to anything */
+               if (h1c->wait_event.events)
+                       conn->xprt->unsubscribe(conn, conn->xprt_ctx,
+                                               h1c->wait_event.events, &h1c->wait_event);
+               if (conn_upgrade_mux_fe(conn, NULL, &h1c->ibuf, ist("h2"), PROTO_MODE_HTTP) != -1) {
+                       /* connection successfully upgraded to H2, this
+                        * mux was already released */
+                       return;
+               }
+               TRACE_ERROR("h2 upgrade failed", H1_EV_H1C_END|H1_EV_H1C_ERR, conn);
+               sess_log(conn->owner); /* Log if the upgrade failed */
+       }
 
-               if (LIST_INLIST(&h1c->buf_wait.list))
-                       LIST_DEL_INIT(&h1c->buf_wait.list);
 
-               h1_release_buf(h1c, &h1c->ibuf);
-               h1_release_buf(h1c, &h1c->obuf);
+       if (LIST_INLIST(&h1c->buf_wait.list))
+               LIST_DEL_INIT(&h1c->buf_wait.list);
 
-               if (h1c->task) {
-                       h1c->task->context = NULL;
-                       task_wakeup(h1c->task, TASK_WOKEN_OTHER);
-                       h1c->task = NULL;
-               }
+       h1_release_buf(h1c, &h1c->ibuf);
+       h1_release_buf(h1c, &h1c->obuf);
 
-               if (h1c->wait_event.tasklet)
-                       tasklet_free(h1c->wait_event.tasklet);
+       if (h1c->task) {
+               h1c->task->context = NULL;
+               task_wakeup(h1c->task, TASK_WOKEN_OTHER);
+               h1c->task = NULL;
+       }
 
-               h1s_destroy(h1c->h1s);
-               if (conn) {
-                       if (h1c->wait_event.events != 0)
-                               conn->xprt->unsubscribe(conn, conn->xprt_ctx, h1c->wait_event.events,
-                                                       &h1c->wait_event);
-                       h1_shutw_conn(conn);
-               }
+       if (h1c->wait_event.tasklet)
+               tasklet_free(h1c->wait_event.tasklet);
 
-               HA_ATOMIC_DEC(&h1c->px_counters->open_conns);
-               pool_free(pool_head_h1c, h1c);
+       h1s_destroy(h1c->h1s);
+       if (conn) {
+               if (h1c->wait_event.events != 0)
+                       conn->xprt->unsubscribe(conn, conn->xprt_ctx, h1c->wait_event.events,
+                                               &h1c->wait_event);
+               h1_shutw_conn(conn);
        }
 
+       HA_ATOMIC_DEC(&h1c->px_counters->open_conns);
+       pool_free(pool_head_h1c, h1c);
+
        if (conn) {
                if (!conn_is_back(conn))
                        LIST_DEL_INIT(&conn->stopping_list);
index 000f231246b0e11f29420139a20e998a6cd81440..4bacc8c2fbfbbb8424a007f93715dcbf32cc1258 100644 (file)
@@ -1161,37 +1161,32 @@ static inline struct h2s *h2c_st_by_id(struct h2c *h2c, int id)
  */
 static void h2_release(struct h2c *h2c)
 {
-       struct connection *conn = NULL;
+       struct connection *conn = h2c->conn;
 
        TRACE_ENTER(H2_EV_H2C_END);
 
-       if (h2c) {
-               conn = h2c->conn;
-
-               TRACE_DEVEL("freeing h2c", H2_EV_H2C_END, conn);
-               hpack_dht_free(h2c->ddht);
+       hpack_dht_free(h2c->ddht);
 
-               if (LIST_INLIST(&h2c->buf_wait.list))
-                       LIST_DEL_INIT(&h2c->buf_wait.list);
+       if (LIST_INLIST(&h2c->buf_wait.list))
+               LIST_DEL_INIT(&h2c->buf_wait.list);
 
-               h2_release_buf(h2c, &h2c->dbuf);
-               h2_release_mbuf(h2c);
+       h2_release_buf(h2c, &h2c->dbuf);
+       h2_release_mbuf(h2c);
 
-               if (h2c->task) {
-                       h2c->task->context = NULL;
-                       task_wakeup(h2c->task, TASK_WOKEN_OTHER);
-                       h2c->task = NULL;
-               }
-               if (h2c->wait_event.tasklet)
-                       tasklet_free(h2c->wait_event.tasklet);
-               if (conn && h2c->wait_event.events != 0)
-                       conn->xprt->unsubscribe(conn, conn->xprt_ctx, h2c->wait_event.events,
-                                               &h2c->wait_event);
+       if (h2c->task) {
+               h2c->task->context = NULL;
+               task_wakeup(h2c->task, TASK_WOKEN_OTHER);
+               h2c->task = NULL;
+       }
+       if (h2c->wait_event.tasklet)
+               tasklet_free(h2c->wait_event.tasklet);
+       if (conn && h2c->wait_event.events != 0)
+               conn->xprt->unsubscribe(conn, conn->xprt_ctx, h2c->wait_event.events,
+                                       &h2c->wait_event);
 
-               HA_ATOMIC_DEC(&h2c->px_counters->open_conns);
+       HA_ATOMIC_DEC(&h2c->px_counters->open_conns);
 
-               pool_free(pool_head_h2c, h2c);
-       }
+       pool_free(pool_head_h2c, h2c);
 
        if (conn) {
                if (!conn_is_back(conn))
index 5c01ae54837b24653f54a8a22a39c207eda2536f..9781075f4b4f9e7adb093245eaef18fdc6f3346e 100644 (file)
@@ -200,22 +200,18 @@ static void mux_pt_destroy(struct mux_pt_ctx *ctx)
 
        TRACE_POINT(PT_EV_CONN_END);
 
-       if (ctx) {
-               /* The connection must be attached to this mux to be released */
-               if (ctx->conn && ctx->conn->ctx == ctx)
-                       conn = ctx->conn;
+       /* The connection must be attached to this mux to be released */
+       if (ctx->conn && ctx->conn->ctx == ctx)
+               conn = ctx->conn;
 
-               TRACE_DEVEL("freeing pt context", PT_EV_CONN_END, conn);
+       tasklet_free(ctx->wait_event.tasklet);
 
-               tasklet_free(ctx->wait_event.tasklet);
-
-               if (conn && ctx->wait_event.events != 0)
-                       conn->xprt->unsubscribe(conn, conn->xprt_ctx, ctx->wait_event.events,
-                                               &ctx->wait_event);
-               BUG_ON(ctx->endp && !(ctx->endp->flags & CS_EP_ORPHAN));
-               cs_endpoint_free(ctx->endp);
-               pool_free(pool_head_pt_ctx, ctx);
-       }
+       if (conn && ctx->wait_event.events != 0)
+               conn->xprt->unsubscribe(conn, conn->xprt_ctx, ctx->wait_event.events,
+                                       &ctx->wait_event);
+       BUG_ON(ctx->endp && !(ctx->endp->flags & CS_EP_ORPHAN));
+       cs_endpoint_free(ctx->endp);
+       pool_free(pool_head_pt_ctx, ctx);
 
        if (conn) {
                conn->mux = NULL;
index aea64910069d59df501376c5c043b83d8cdd07eb..58e4759d04947984f658cf9b772ec4615155b64f 100644 (file)
@@ -495,39 +495,32 @@ static inline int qcc_may_expire(struct qcc *qcc)
  */
 static void qc_release(struct qcc *qcc)
 {
-       struct connection *conn = NULL;
+       struct connection *conn = qcc->conn;
+       struct eb64_node *node;
 
        TRACE_ENTER(QMUX_EV_QCC_END);
 
-       if (qcc) {
-               struct eb64_node *node;
-
-               conn = qcc->conn;
-
-               TRACE_DEVEL("freeing qcc", QMUX_EV_QCC_END, conn);
+       if (qcc->app_ops && qcc->app_ops->release)
+               qcc->app_ops->release(qcc->ctx);
 
-               if (qcc->app_ops && qcc->app_ops->release)
-                       qcc->app_ops->release(qcc->ctx);
-
-               if (qcc->task) {
-                       task_destroy(qcc->task);
-                       qcc->task = NULL;
-               }
-
-               if (qcc->wait_event.tasklet)
-                       tasklet_free(qcc->wait_event.tasklet);
+       if (qcc->task) {
+               task_destroy(qcc->task);
+               qcc->task = NULL;
+       }
 
-               /* liberate remaining qcs instances */
-               node = eb64_first(&qcc->streams_by_id);
-               while (node) {
-                       struct qc_stream_desc *stream = eb64_entry(node, struct qc_stream_desc, by_id);
-                       node = eb64_next(node);
-                       qcs_free(stream->ctx);
-               }
+       if (qcc->wait_event.tasklet)
+               tasklet_free(qcc->wait_event.tasklet);
 
-               pool_free(pool_head_qcc, qcc);
+       /* liberate remaining qcs instances */
+       node = eb64_first(&qcc->streams_by_id);
+       while (node) {
+               struct qc_stream_desc *stream = eb64_entry(node, struct qc_stream_desc, by_id);
+               node = eb64_next(node);
+               qcs_free(stream->ctx);
        }
 
+       pool_free(pool_head_qcc, qcc);
+
        if (conn) {
                LIST_DEL_INIT(&conn->stopping_list);