]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Add data stack frames when searching messages
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 27 Dec 2022 10:13:26 +0000 (05:13 -0500)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 11 Jan 2023 21:50:37 +0000 (23:50 +0200)
This makes sure memory usage doesn't increase too much while searching a
large number of messages. A few of these data stack frames are likely
unnecessary, but it's better to be safe.

src/lib-storage/index/index-search.c
src/lib-storage/mail-storage.c

index 37c21f36a3a8f5a115aa50f30fc5d2792bdaa4c6..899df4c278161d3ff8bb15a24701e78fbb663f76 100644 (file)
@@ -1676,10 +1676,18 @@ static int search_more_with_mail(struct index_search_context *ctx,
 
        cost1 = search_get_cost(mail->transaction);
        ret = -1;
-       while (box->v.search_next_update_seq(_ctx)) {
+       for (;;) {
+               bool more;
+               T_BEGIN {
+                       more = box->v.search_next_update_seq(_ctx);
+               } T_END;
+               if (!more)
+                       break;
                mail_set_seq(mail, _ctx->seq);
 
-               ret = box->v.search_next_match_mail(_ctx, mail);
+               T_BEGIN {
+                       ret = box->v.search_next_match_mail(_ctx, mail);
+               } T_END;
                if (ret != 0)
                        break;
 
@@ -1772,7 +1780,9 @@ static int search_more_with_prefetching(struct index_search_context *ctx,
                array_pop_front(&ctx->mail_ctx.mails);
                array_push_back(&ctx->mail_ctx.mails, mail_r);
        }
-       index_mail_update_access_parts_post(*mail_r);
+       T_BEGIN {
+               index_mail_update_access_parts_post(*mail_r);
+       } T_END;
        return 1;
 }
 
@@ -1870,8 +1880,9 @@ bool index_storage_search_next_nonblock(struct mail_search_context *_ctx,
        }
 
        if (!ctx->sorted) {
-               while ((ret = search_more(ctx, &mail)) > 0)
+               while ((ret = search_more(ctx, &mail)) > 0) T_BEGIN {
                        index_sort_list_add(_ctx->sort_program, mail);
+               } T_END;
 
                if (ret == 0) {
                        *tryagain_r = TRUE;
index 6743942c106eb02720c19980f7c661d8ad0b2925..a900662b0f6ddb6b2c1605a26c52af123f1d420d 100644 (file)
@@ -2492,11 +2492,15 @@ bool mailbox_search_next_nonblock(struct mail_search_context *ctx,
                                  struct mail **mail_r, bool *tryagain_r)
 {
        struct mailbox *box = ctx->transaction->box;
+       bool ret;
 
        *mail_r = NULL;
        *tryagain_r = FALSE;
 
-       if (!box->v.search_next_nonblock(ctx, mail_r, tryagain_r))
+       T_BEGIN {
+               ret = box->v.search_next_nonblock(ctx, mail_r, tryagain_r);
+       } T_END;
+       if (!ret)
                return FALSE;
        else {
                mailbox_search_results_add(ctx, (*mail_r)->uid);