]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: acme: memory leak from the config parser
authorWilliam Lallemand <wlallemand@haproxy.com>
Thu, 9 Oct 2025 09:39:17 +0000 (11:39 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 9 Oct 2025 10:04:22 +0000 (12:04 +0200)
This patch fixes some memory leaks in the configuration parser:

- deinit_acme() was never called
- add ha_free() before every strdup() for section overwrite
- lacked some free() in deinit_acme()

src/acme.c

index 62917c335528b7ca7c7afa88c0330e21ab220744..816de1e28dbf55620d6d799e36c1e5543d33fc79 100644 (file)
@@ -304,7 +304,8 @@ static int cfg_parse_acme(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
 
-               cur_acme->filename = (char *)file;
+               ha_free(&cur_acme->filename);
+               cur_acme->filename = strdup(file);
                cur_acme->linenum = linenum;
 
                goto out;
@@ -369,6 +370,7 @@ static int cfg_parse_acme_kws(char **args, int section_type, struct proxy *curpx
                }
                if (alertif_too_many_args(1, file, linenum, args, &err_code))
                        goto out;
+               ha_free(&cur_acme->directory);
                cur_acme->directory = strdup(args[1]);
                if (!cur_acme->directory) {
                        err_code |= ERR_ALERT | ERR_FATAL;
@@ -385,6 +387,7 @@ static int cfg_parse_acme_kws(char **args, int section_type, struct proxy *curpx
                if (alertif_too_many_args(1, file, linenum, args, &err_code))
                        goto out;
 
+               ha_free(&cur_acme->account.contact);
                cur_acme->account.contact = strdup(args[1]);
                if (!cur_acme->account.contact) {
                        err_code |= ERR_ALERT | ERR_FATAL;
@@ -401,6 +404,7 @@ static int cfg_parse_acme_kws(char **args, int section_type, struct proxy *curpx
                if (alertif_too_many_args(2, file, linenum, args, &err_code))
                        goto out;
 
+               ha_free(&cur_acme->account.file);
                cur_acme->account.file = strdup(args[1]);
                if (!cur_acme->account.file) {
                        err_code |= ERR_ALERT | ERR_FATAL;
@@ -417,6 +421,7 @@ static int cfg_parse_acme_kws(char **args, int section_type, struct proxy *curpx
                if (alertif_too_many_args(2, file, linenum, args, &err_code))
                        goto out;
 
+               ha_free(&cur_acme->challenge);
                cur_acme->challenge = strdup(args[1]);
                if (!cur_acme->challenge) {
                        err_code |= ERR_ALERT | ERR_FATAL;
@@ -433,6 +438,7 @@ static int cfg_parse_acme_kws(char **args, int section_type, struct proxy *curpx
                if (alertif_too_many_args(1, file, linenum, args, &err_code))
                        goto out;
 
+               ha_free(&cur_acme->map);
                cur_acme->map = strdup(args[1]);
                if (!cur_acme->map) {
                        err_code |= ERR_ALERT | ERR_FATAL;
@@ -789,19 +795,25 @@ void deinit_acme()
        while (acme_cfgs) {
 
                next = acme_cfgs->next;
+               ha_free(&acme_cfgs->filename);
                ha_free(&acme_cfgs->name);
                ha_free(&acme_cfgs->directory);
                ha_free(&acme_cfgs->account.contact);
                ha_free(&acme_cfgs->account.file);
                ha_free(&acme_cfgs->account.thumbprint);
+               EVP_PKEY_free(acme_cfgs->account.pkey);
                ha_free(&acme_cfgs->vars);
                ha_free(&acme_cfgs->provider);
+               ha_free(&acme_cfgs->challenge);
+               ha_free(&acme_cfgs->map);
 
                free(acme_cfgs);
                acme_cfgs = next;
        }
 }
 
+REGISTER_POST_DEINIT(deinit_acme);
+
 static struct cfg_kw_list cfg_kws_acme = {ILH, {
        { CFG_ACME, "directory",  cfg_parse_acme_kws },
        { CFG_ACME, "contact",  cfg_parse_acme_kws },