]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: conn-stream: Use a dedicated function to conditionally remove a CS
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 12 Apr 2022 16:09:48 +0000 (18:09 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 13 Apr 2022 13:10:16 +0000 (15:10 +0200)
cs_free_cond() must now be used to remove a CS. cs_free() may be used on
error path to release a freshly allocated but unused CS. But in all other
cases cs_free_cond() must be used. This function takes care to release the
CS if it is possible (no app and detached from any endpoint).

In fact, this function is only used internally. From the outside,
cs_detach_* functions are used.

src/conn_stream.c

index 0c6f1936a391e6ab9f6716d93d6afa8dcee4f9b3..572c13e4f38f1a7dcaa5f3f009d968a10cbfed45 100644 (file)
@@ -244,6 +244,15 @@ void cs_free(struct conn_stream *cs)
        pool_free(pool_head_connstream, cs);
 }
 
+/* Conditionally removes a conn-stream if it is detached and it there is no app
+ * layer defined. Except on error path, this one must be used.
+ */
+static void cs_free_cond(struct conn_stream *cs)
+{
+       if (!cs->app && (!cs->endp || (cs->endp->flags & CS_EP_DETACHED)))
+               cs_free(cs);
+}
+
 
 /* Attaches a conn_stream to a mux endpoint and sets the endpoint ctx. Returns
  * -1 on error and 0 on sucess. CS_EP_DETACHED flag is removed. This function is
@@ -385,9 +394,7 @@ void cs_detach_endp(struct conn_stream *cs)
        if (cs_strm(cs))
                cs->ops = &cs_app_embedded_ops;
        cs->data_cb = NULL;
-
-       if (cs->app == NULL)
-               cs_free(cs);
+       cs_free_cond(cs);
 }
 
 /* Detaches the conn_stream from the app layer. If there is no endpoint attached
@@ -404,9 +411,7 @@ void cs_detach_app(struct conn_stream *cs)
                tasklet_free(cs->wait_event.tasklet);
        cs->wait_event.tasklet = NULL;
        cs->wait_event.events = 0;
-
-       if (!cs->endp || (cs->endp->flags & CS_EP_DETACHED))
-               cs_free(cs);
+       cs_free_cond(cs);
 }
 
 /* Resets the conn-stream endpoint. It happens when the app layer want to renew