]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: httpclient: test if started during stop_and_destroy()
authorWilliam Lallemand <wlallemand@haproxy.org>
Tue, 28 Sep 2021 10:15:37 +0000 (12:15 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Wed, 6 Oct 2021 13:15:03 +0000 (15:15 +0200)
If the httpclient was never started, it is safe to destroy completely
the httpclient.

include/haproxy/http_client-t.h
src/http_client.c

index df25de397eedf016e650fa045688c417460a7086..fa0f8fbdd422aed9e7d0f3d0d1e4794cf2e99c65 100644 (file)
@@ -35,7 +35,8 @@ struct httpclient {
 #define    HTTPCLIENT_FA_AUTOKILL     0x00000002   /* sets the applet to destroy the httpclient struct itself */
 
 /* status (FS) */
-#define    HTTPCLIENT_FS_ENDED        0x00010000 /* the httpclient is stopped */
+#define    HTTPCLIENT_FS_STARTED      0x00010000 /* the httpclient was started */
+#define    HTTPCLIENT_FS_ENDED        0x00020000 /* the httpclient is stopped */
 
 /* States of the HTTP Client Appctx */
 enum {
index 6055a01cc38fbdd901b8915c9e2a6d4f74b465e1..24d8fbe3b92dbd04e1f7df07506005d1b2b56d3a 100644 (file)
@@ -390,6 +390,7 @@ struct appctx *httpclient_start(struct httpclient *hc)
 
        task_wakeup(s->task, TASK_WOKEN_INIT);
        hc->appctx = appctx;
+       hc->flags |= HTTPCLIENT_FS_STARTED;
        appctx->ctx.httpclient.ptr = hc;
        appctx->st0 = HTTPCLIENT_S_REQ;
 
@@ -417,8 +418,8 @@ out:
 void httpclient_stop_and_destroy(struct httpclient *hc)
 {
 
-       /* The httpclient was already stopped, we can safely destroy it */
-       if (hc->flags & HTTPCLIENT_FS_ENDED) {
+       /* The httpclient was already stopped or never started, we can safely destroy it */
+       if (hc->flags & HTTPCLIENT_FS_ENDED || !(hc->flags & HTTPCLIENT_FS_STARTED)) {
                httpclient_destroy(hc);
        } else {
        /* if the client wasn't stopped, ask for a stop and destroy */