]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm: Don't use data stack for permanent memory allocations in init()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 27 Dec 2022 11:15:38 +0000 (06:15 -0500)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 11 Jan 2023 22:02:11 +0000 (00:02 +0200)
Until now this didn't really matter, since callers weren't freeing the data
stack memory anyway. The following commit changes this though.

src/doveadm/doveadm-mail-fetch.c
src/doveadm/doveadm-mail-mailbox-cache.c

index 86e1f6773710d807207c195477b21524d51f581a..f051097488ccf4f33877cfa4af5f0c971ec6da58 100644 (file)
@@ -544,8 +544,8 @@ static void parse_fetch_fields(struct fetch_cmd_context *ctx, const char *const
        i_zero(&body_field);
        body_field.print = fetch_body_field;
 
-       t_array_init(&ctx->fields, 32);
-       t_array_init(&ctx->header_fields, 32);
+       p_array_init(&ctx->fields, ctx->ctx.pool, 32);
+       p_array_init(&ctx->header_fields, ctx->ctx.pool, 32);
        for (; *fields != NULL; fields++) {
                name = t_str_lcase(*fields);
 
@@ -554,13 +554,14 @@ static void parse_fetch_fields(struct fetch_cmd_context *ctx, const char *const
                        ctx->wanted_fields |= field->wanted_fields;
                        array_push_back(&ctx->fields, field);
                } else if (str_begins(name, "hdr.", &name)) {
-                       hdr_field.name = name;
+                       hdr_field.name = p_strdup(ctx->ctx.pool, name);
                        array_push_back(&ctx->fields, &hdr_field);
-                       name = t_strcut(name, '.');
+                       name = p_strdup(ctx->ctx.pool, t_strcut(name, '.'));
                        array_push_back(&ctx->header_fields, &name);
                } else if (str_begins(name, "body.", &section) ||
                           str_begins(name, "binary.", &section)) {
-                       body_field.name = t_strarray_join(t_strsplit(name, ","), " ");
+                       body_field.name = p_strdup(ctx->ctx.pool,
+                               t_strarray_join(t_strsplit(name, ","), " "));
 
                        if (imap_msgpart_parse(section, &msgpart) < 0) {
                                print_fetch_fields();
index 7be26da4b7718ca7d251b93bf6e1256607c36e30..7cef0a4f99fbf16b6b8af0d049e4ccf6f97e6933 100644 (file)
@@ -84,7 +84,7 @@ static void cmd_mailbox_cache_decision_init(struct doveadm_mail_cmd_context *_ct
        if (!ctx->all_fields) {
                if (!doveadm_cmd_param_str(cctx, "fieldstr", &value_str))
                        i_fatal_status(EX_USAGE, "Missing fields parameter");
-               ctx->fields = t_strsplit_spaces(value_str, ", ");
+               ctx->fields = (const char *const *)p_strsplit_spaces(_ctx->pool, value_str, ", ");
        }
 
        if (!doveadm_cmd_param_array(cctx, "mailbox", &ctx->boxes))