]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm: doveadm-stats - Allocate field_types
authorAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 8 Sep 2021 06:53:12 +0000 (09:53 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 8 Sep 2021 07:47:56 +0000 (10:47 +0300)
field_types was function local variable that got used outside
of function. Change to use datastack allocation instead to
keep it valid after leaving function.

Broken in e9a46e3a6df2edd6cb68a8fc04a5e8e4564a9d5e

src/doveadm/doveadm-stats.c

index a8ab6c1526badcafe439f8b9eaa057b61e9a7f89..6652a9e54e239df211ebca384324ab222d3ff4a5 100644 (file)
@@ -154,23 +154,22 @@ static int build_stats_dump_cmd(struct stats_cmd_context *ctx,
        fields = t_strsplit_spaces(fields_raw, ", ");
        data->fields = fields;
        data->field_count = str_array_length(fields);
-       enum doveadm_dump_field_type field_types[data->field_count];
+       data->field_types =
+               t_malloc0(sizeof(enum doveadm_dump_field_type) * data->field_count);
        ctx->data = data;
        ctx->cmd = init_stats_cmd();
        str_append(ctx->cmd, reset ? "DUMP-RESET" : "DUMP");
-       i_zero(&field_types);
        unsigned int i;
        for (i = 0; i < data->field_count; i++) {
                str_append_c(ctx->cmd, '\t');
                if (strcmp(fields[i], "stddev") == 0) {
-                       field_types[i] = DOVEADM_DUMP_FIELD_TYPE_STDDEV;
+                       data->field_types[i] = DOVEADM_DUMP_FIELD_TYPE_STDDEV;
                        str_append(ctx->cmd, "variance");
                } else {
                        str_append_tabescaped(ctx->cmd, fields[i]);
                }
        }
        str_append_c(ctx->cmd, '\n');
-       data->field_types = field_types;
        return 0;
 }