From: Timo Sirainen Date: Tue, 27 Dec 2022 10:13:26 +0000 (-0500) Subject: lib-storage: Add data stack frames when searching messages X-Git-Tag: 2.4.0~3221 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=abc2871945fdeeb6641ed7add18883a6eaac612b;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Add data stack frames when searching messages 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. --- diff --git a/src/lib-storage/index/index-search.c b/src/lib-storage/index/index-search.c index 37c21f36a3..899df4c278 100644 --- a/src/lib-storage/index/index-search.c +++ b/src/lib-storage/index/index-search.c @@ -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; diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 6743942c10..a900662b0f 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -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);