From: Timo Sirainen Date: Tue, 27 Dec 2022 11:15:38 +0000 (-0500) Subject: doveadm: Don't use data stack for permanent memory allocations in init() X-Git-Tag: 2.4.0~3210 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c6a609e2a1ebbb563b1b754f785e6fc6e7698fc5;p=thirdparty%2Fdovecot%2Fcore.git doveadm: Don't use data stack for permanent memory allocations in init() Until now this didn't really matter, since callers weren't freeing the data stack memory anyway. The following commit changes this though. --- diff --git a/src/doveadm/doveadm-mail-fetch.c b/src/doveadm/doveadm-mail-fetch.c index 86e1f67737..f051097488 100644 --- a/src/doveadm/doveadm-mail-fetch.c +++ b/src/doveadm/doveadm-mail-fetch.c @@ -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.", §ion) || str_begins(name, "binary.", §ion)) { - 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(); diff --git a/src/doveadm/doveadm-mail-mailbox-cache.c b/src/doveadm/doveadm-mail-mailbox-cache.c index 7be26da4b7..7cef0a4f99 100644 --- a/src/doveadm/doveadm-mail-mailbox-cache.c +++ b/src/doveadm/doveadm-mail-mailbox-cache.c @@ -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))