]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: acme: free acme_ctx once the task is done
authorWilliam Lallemand <wlallemand@haproxy.com>
Wed, 16 Apr 2025 15:54:34 +0000 (17:54 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Wed, 16 Apr 2025 16:08:01 +0000 (18:08 +0200)
Free the acme_ctx task context once the task is done.
It frees everything but the config and the httpclient,
everything else is free.

The ckch_store is freed in case of error, but when the task is
successful, the ptr is set to NULL to prevent the free once inserted in
the tree.

src/acme.c

index 47520a738e87fe4175bdf0eb13d502abc3823972..1e45b2d44491518fa707db72b86faeb4702ffa52 100644 (file)
@@ -491,6 +491,44 @@ INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws_acme);
 REGISTER_CONFIG_SECTION("acme", cfg_parse_acme, cfg_postsection_acme);
 
 
+/* free acme_ctx and its content
+ *
+ * Only acme_cfg and the httpclient is not free
+ *
+ */
+static void acme_ctx_destroy(struct acme_ctx *ctx)
+{
+       struct acme_auth *auth;
+
+       istfree(&ctx->ressources.newNonce);
+       istfree(&ctx->ressources.newAccount);
+       istfree(&ctx->ressources.newOrder);
+       istfree(&ctx->nonce);
+       istfree(&ctx->kid);
+       istfree(&ctx->order);
+
+       auth = ctx->auths;
+       while (auth) {
+               struct acme_auth *next;
+
+               istfree(&auth->auth);
+               istfree(&auth->chall);
+               istfree(&auth->token);
+               next = auth->next;
+               free(auth);
+               auth = next;
+       }
+
+       istfree(&ctx->finalize);
+       istfree(&ctx->certificate);
+
+       ckch_store_free(ctx->store);
+
+       X509_REQ_free(ctx->req);
+
+       free(ctx);
+}
+
 static void acme_httpclient_end(struct httpclient *hc)
 {
        struct task *task = hc->caller;
@@ -627,6 +665,8 @@ int acme_update_certificate(struct task *task, struct acme_ctx *ctx, char **errm
 
        send_log(NULL, LOG_NOTICE,"acme: %s: Successful update of the certificate.\n", ctx->store->path);
 
+       ctx->store = NULL;
+
        ret = 0;
 
 error:
@@ -1695,6 +1735,7 @@ retry:
 
        return task;
 end:
+       acme_ctx_destroy(ctx);
        task_destroy(task);
        task = NULL;