MINOR: httpclient: test if started during stop_and_destroy()

If the httpclient was never started, it is safe to destroy completely
the httpclient.
This commit is contained in:
William Lallemand 2021-09-28 12:15:37 +02:00
parent ecb83e13eb
commit b8b1370307
2 changed files with 5 additions and 3 deletions

View File

@ -35,7 +35,8 @@ struct httpclient {
#define HTTPCLIENT_FA_AUTOKILL 0x00000002 /* sets the applet to destroy the httpclient struct itself */ #define HTTPCLIENT_FA_AUTOKILL 0x00000002 /* sets the applet to destroy the httpclient struct itself */
/* status (FS) */ /* 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 */ /* States of the HTTP Client Appctx */
enum { enum {

View File

@ -390,6 +390,7 @@ struct appctx *httpclient_start(struct httpclient *hc)
task_wakeup(s->task, TASK_WOKEN_INIT); task_wakeup(s->task, TASK_WOKEN_INIT);
hc->appctx = appctx; hc->appctx = appctx;
hc->flags |= HTTPCLIENT_FS_STARTED;
appctx->ctx.httpclient.ptr = hc; appctx->ctx.httpclient.ptr = hc;
appctx->st0 = HTTPCLIENT_S_REQ; appctx->st0 = HTTPCLIENT_S_REQ;
@ -417,8 +418,8 @@ out:
void httpclient_stop_and_destroy(struct httpclient *hc) void httpclient_stop_and_destroy(struct httpclient *hc)
{ {
/* The httpclient was already stopped, we can safely destroy it */ /* The httpclient was already stopped or never started, we can safely destroy it */
if (hc->flags & HTTPCLIENT_FS_ENDED) { if (hc->flags & HTTPCLIENT_FS_ENDED || !(hc->flags & HTTPCLIENT_FS_STARTED)) {
httpclient_destroy(hc); httpclient_destroy(hc);
} else { } else {
/* if the client wasn't stopped, ask for a stop and destroy */ /* if the client wasn't stopped, ask for a stop and destroy */