]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dict-sql: Don't return iterated values from data stack
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 27 Dec 2022 20:25:31 +0000 (15:25 -0500)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 11 Jan 2023 21:50:37 +0000 (23:50 +0200)
This just causes data stack to grow while iterating. Use a memory pool
for the last returned value instead.

src/lib-dict-backend/dict-sql.c

index 8d685cd5b51daf5bec710e98f7b27bb481791db1..052d36b025c74a932220e61b939721a5f0ef049e 100644 (file)
@@ -45,6 +45,7 @@ struct sql_dict_iterate_context {
 
        struct sql_result *result;
        string_t *key;
+       pool_t value_pool;
        const struct dict_sql_map *map;
        size_t key_prefix_len, pattern_prefix_len;
        unsigned int sql_fields_start_idx, next_map_idx;
@@ -828,6 +829,7 @@ sql_dict_iterate_init(struct dict *_dict,
        ctx->path = p_strdup(pool, path);
 
        ctx->key = str_new(pool, 256);
+       ctx->value_pool = pool_alloconly_create("sql dict iterate value", 256);
        return &ctx->ctx;
 }
 
@@ -917,8 +919,9 @@ static bool sql_dict_iterate(struct dict_iterate_context *_ctx,
 
        *key_r = str_c(ctx->key);
        if ((ctx->flags & DICT_ITERATE_FLAG_NO_VALUE) == 0) {
+               p_clear(ctx->value_pool);
                *values_r = sql_dict_result_unescape_values(ctx->map,
-                       pool_datastack_create(), ctx->result);
+                               ctx->value_pool, ctx->result);
        }
        return TRUE;
 }
@@ -935,6 +938,7 @@ static int sql_dict_iterate_deinit(struct dict_iterate_context *_ctx,
                sql_result_unref(ctx->result);
        ctx->destroyed = TRUE;
 
+       pool_unref(&ctx->value_pool);
        pool_t pool_copy = ctx->pool;
        pool_unref(&pool_copy);
        return ret;