From: Richard Russon Date: Mon, 27 Aug 2018 20:35:07 +0000 (+0100) Subject: free on mx_mbox_close X-Git-Tag: 2019-10-25~676^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4bdd49367991cdacae30d0d42203e405daba8318;p=neomutt free on mx_mbox_close --- diff --git a/commands.c b/commands.c index 2f3775390..6331bb3a2 100644 --- a/commands.c +++ b/commands.c @@ -1003,8 +1003,7 @@ int mutt_save_message(struct Header *h, bool delete, bool decode, bool decrypt) { if (mutt_save_message_ctx(h, delete, decode, decrypt, savectx) != 0) { - mx_mbox_close(savectx, NULL); - FREE(&savectx); + mx_mbox_close(&savectx, NULL); return -1; } #ifdef USE_COMPRESSED @@ -1053,16 +1052,14 @@ int mutt_save_message(struct Header *h, bool delete, bool decode, bool decrypt) #endif if (rc != 0) { - mx_mbox_close(savectx, NULL); - FREE(&savectx); + mx_mbox_close(&savectx, NULL); return -1; } } const bool need_mailbox_cleanup = ((savectx->magic == MUTT_MBOX) || (savectx->magic == MUTT_MMDF)); - mx_mbox_close(savectx, NULL); - FREE(&savectx); + mx_mbox_close(&savectx, NULL); if (need_mailbox_cleanup) mutt_mailbox_cleanup(buf, &st); diff --git a/compose.c b/compose.c index 6690cb265..5322b7ed8 100644 --- a/compose.c +++ b/compose.c @@ -1460,8 +1460,7 @@ int mutt_compose_menu(struct Header *msg, char *fcc, size_t fcclen, if (!ctx->msgcount) { - mx_mbox_close(ctx, NULL); - FREE(&ctx); + mx_mbox_close(&ctx, NULL); mutt_error(_("No messages in that folder")); break; } @@ -1505,10 +1504,12 @@ int mutt_compose_menu(struct Header *msg, char *fcc, size_t fcclen, menu->redraw |= REDRAW_FULL; if (close == OP_QUIT) - mx_mbox_close(Context, NULL); + mx_mbox_close(&Context, NULL); else + { mx_fastclose_mailbox(Context); - FREE(&Context); + FREE(&Context); + } /* go back to the folder we started from */ Context = this; diff --git a/curs_main.c b/curs_main.c index bcf47e6b8..f4d3bed32 100644 --- a/curs_main.c +++ b/curs_main.c @@ -521,7 +521,7 @@ static int main_change_folder(struct Menu *menu, int op, char *buf, new_last_folder = mutt_str_strdup(Context->path); *oldcount = Context ? Context->msgcount : 0; - int check = mx_mbox_close(Context, index_hint); + int check = mx_mbox_close(&Context, index_hint); if (check != 0) { if (check == MUTT_NEW_MAIL || check == MUTT_REOPENED) @@ -532,7 +532,6 @@ static int main_change_folder(struct Menu *menu, int op, char *buf, menu->redraw |= REDRAW_INDEX | REDRAW_STATUS; return 0; } - FREE(&Context); FREE(&LastFolder); LastFolder = new_last_folder; } @@ -1591,7 +1590,7 @@ int mutt_index_menu(void) mutt_startup_shutdown_hook(MUTT_SHUTDOWN_HOOK); - if (!Context || (check = mx_mbox_close(Context, &index_hint)) == 0) + if (!Context || (check = mx_mbox_close(&Context, &index_hint)) == 0) done = true; else { @@ -1731,13 +1730,12 @@ int mutt_index_menu(void) case OP_MAIN_IMAP_LOGOUT_ALL: if (Context && Context->magic == MUTT_IMAP) { - if (mx_mbox_close(Context, &index_hint) != 0) + if (mx_mbox_close(&Context, &index_hint) != 0) { OptSearchInvalid = true; menu->redraw = REDRAW_FULL; break; } - FREE(&Context); } imap_logout_all(); mutt_message(_("Logged out of IMAP servers")); diff --git a/editmsg.c b/editmsg.c index 8410c8d49..353a3f3a9 100644 --- a/editmsg.c +++ b/editmsg.c @@ -97,8 +97,7 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Heade rc = mutt_append_message(tmpctx, ctx, cur, 0, chflags); oerrno = errno; - mx_mbox_close(tmpctx, NULL); - FREE(&tmpctx); + mx_mbox_close(&tmpctx, NULL); if (rc == -1) { @@ -219,8 +218,7 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Heade if (!msg) { mutt_error(_("Can't append to folder: %s"), strerror(errno)); - mx_mbox_close(tmpctx, NULL); - FREE(&tmpctx); + mx_mbox_close(&tmpctx, NULL); goto bail; } @@ -234,8 +232,7 @@ static int edit_or_view_one_message(bool edit, struct Context *ctx, struct Heade rc = mx_msg_commit(tmpctx, msg); mx_msg_close(tmpctx, &msg); - mx_mbox_close(tmpctx, NULL); - FREE(&tmpctx); + mx_mbox_close(&tmpctx, NULL); bail: if (fp) diff --git a/mailbox.c b/mailbox.c index 8ebdb24af..863dfe2a0 100644 --- a/mailbox.c +++ b/mailbox.c @@ -365,8 +365,7 @@ static int mailbox_mbox_check(struct Mailbox *mailbox, struct stat *sb, bool che mailbox->msg_unread = ctx->unread; mailbox->msg_flagged = ctx->flagged; mailbox->stats_last_checked = ctx->mtime; - mx_mbox_close(ctx, NULL); - FREE(&ctx); + mx_mbox_close(&ctx, NULL); } } diff --git a/mutt_attach.c b/mutt_attach.c index 75c7061a1..38360fca1 100644 --- a/mutt_attach.c +++ b/mutt_attach.c @@ -809,8 +809,7 @@ int mutt_save_attachment(FILE *fp, struct Body *m, char *path, int flags, struct msg = mx_msg_open_new(ctx, hn, is_from(buf, NULL, 0, NULL) ? 0 : MUTT_ADD_FROM); if (!msg) { - mx_mbox_close(ctx, NULL); - FREE(&ctx); + mx_mbox_close(&ctx, NULL); return -1; } if ((ctx->magic == MUTT_MBOX) || (ctx->magic == MUTT_MMDF)) @@ -827,8 +826,7 @@ int mutt_save_attachment(FILE *fp, struct Body *m, char *path, int flags, struct } mx_msg_close(ctx, &msg); - mx_mbox_close(ctx, NULL); - FREE(&ctx); + mx_mbox_close(&ctx, NULL); return r; } else diff --git a/mx.c b/mx.c index 9618822fe..009b3b28e 100644 --- a/mx.c +++ b/mx.c @@ -469,15 +469,13 @@ static int trash_append(struct Context *ctx) { if (mutt_append_message(ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1) { - mx_mbox_close(ctx_trash, NULL); - FREE(&ctx_trash); + mx_mbox_close(&ctx_trash, NULL); return -1; } } } - mx_mbox_close(ctx_trash, NULL); - FREE(&ctx_trash); + mx_mbox_close(&ctx_trash, NULL); } else { @@ -489,26 +487,28 @@ static int trash_append(struct Context *ctx) } /** - * mx_mbox_close - save changes and close mailbox + * mx_mbox_close - Save changes and close mailbox * @param ctx Mailbox * @param index_hint Current email * @retval 0 Success * @retval -1 Failure */ -int mx_mbox_close(struct Context *ctx, int *index_hint) +int mx_mbox_close(struct Context **pctx, int *index_hint) { + if (!pctx || !*pctx) + return 0; + + struct Context *ctx = *pctx; int i, move_messages = 0, purge = 1, read_msgs = 0; char mbox[PATH_MAX]; char buf[PATH_MAX + 64]; - if (!ctx) - return 0; - ctx->closing = true; if (ctx->readonly || ctx->dontwrite || ctx->append) { mx_fastclose_mailbox(ctx); + FREE(pctx); return 0; } @@ -659,16 +659,14 @@ int mx_mbox_close(struct Context *ctx, int *index_hint) } else { - mx_mbox_close(f, NULL); - FREE(&f); + mx_mbox_close(&f, NULL); ctx->closing = false; return -1; } } } - mx_mbox_close(f, NULL); - FREE(&f); + mx_mbox_close(&f, NULL); } } else if (!ctx->changed && ctx->deleted == 0) @@ -678,6 +676,7 @@ int mx_mbox_close(struct Context *ctx, int *index_hint) if (ctx->magic == MUTT_MBOX || ctx->magic == MUTT_MMDF) mbox_reset_atime(ctx, NULL); mx_fastclose_mailbox(ctx); + FREE(pctx); return 0; } @@ -762,6 +761,7 @@ int mx_mbox_close(struct Context *ctx, int *index_hint) #endif mx_fastclose_mailbox(ctx); + FREE(pctx); return 0; } diff --git a/mx.h b/mx.h index f69e3ba68..ae19d04ec 100644 --- a/mx.h +++ b/mx.h @@ -229,7 +229,7 @@ struct MxOps /* Wrappers for the Mailbox API, see MxOps */ int mx_mbox_check (struct Context *ctx, int *index_hint); -int mx_mbox_close (struct Context *ctx, int *index_hint); +int mx_mbox_close (struct Context **pctx, int *index_hint); struct Context *mx_mbox_open (const char *path, int flags); int mx_mbox_sync (struct Context *ctx, int *index_hint); int mx_msg_close (struct Context *ctx, struct Message **msg); diff --git a/pop/pop.c b/pop/pop.c index d39ad4a9e..8e34ded73 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -1010,8 +1010,7 @@ void pop_fetch_mail(void) if (ret == -1) { - mx_mbox_close(ctx, NULL); - FREE(&ctx); + mx_mbox_close(&ctx, NULL); goto fail; } if (ret == -2) @@ -1032,8 +1031,7 @@ void pop_fetch_mail(void) msgbuf, i - last, msgs - last); } - mx_mbox_close(ctx, NULL); - FREE(&ctx); + mx_mbox_close(&ctx, NULL); if (rset) { diff --git a/postpone.c b/postpone.c index 80a7aee85..28de7cd28 100644 --- a/postpone.c +++ b/postpone.c @@ -301,8 +301,7 @@ int mutt_get_postponed(struct Context *ctx, struct Header *hdr, if (!PostContext->msgcount) { PostCount = 0; - mx_mbox_close(PostContext, NULL); - FREE(&PostContext); + mx_mbox_close(&PostContext, NULL); mutt_error(_("No postponed messages")); return -1; } @@ -314,8 +313,7 @@ int mutt_get_postponed(struct Context *ctx, struct Header *hdr, } else if (!(h = select_msg())) { - mx_mbox_close(PostContext, NULL); - FREE(&PostContext); + mx_mbox_close(&PostContext, NULL); return -1; } @@ -336,11 +334,9 @@ int mutt_get_postponed(struct Context *ctx, struct Header *hdr, /* avoid the "purge deleted messages" prompt */ opt_delete = Delete; Delete = MUTT_YES; - mx_mbox_close(PostContext, NULL); + mx_mbox_close(&PostContext, NULL); Delete = opt_delete; - FREE(&PostContext); - struct ListNode *np, *tmp; STAILQ_FOREACH_SAFE(np, &hdr->env->userhdrs, entries, tmp) { diff --git a/sendlib.c b/sendlib.c index 18424d623..ad48d3a19 100644 --- a/sendlib.c +++ b/sendlib.c @@ -3193,8 +3193,7 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid, if (!tempfp) { mutt_perror(tempfile); - mx_mbox_close(f, NULL); - FREE(&f); + mx_mbox_close(&f, NULL); goto done; } /* remember new mail status before appending message */ @@ -3210,8 +3209,7 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid, if (!msg) { mutt_file_fclose(&tempfp); - mx_mbox_close(f, NULL); - FREE(&f); + mx_mbox_close(&f, NULL); goto done; } @@ -3329,8 +3327,7 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid, unlink(tempfile); mx_msg_commit(f, msg); /* XXX really? */ mx_msg_close(f, &msg); - mx_mbox_close(f, NULL); - FREE(&f); + mx_mbox_close(&f, NULL); goto done; } @@ -3361,8 +3358,7 @@ int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid, else if (finalpath) *finalpath = mutt_str_strdup(msg->committed_path); mx_msg_close(f, &msg); - mx_mbox_close(f, NULL); - FREE(&f); + mx_mbox_close(&f, NULL); if (!post && need_mailbox_cleanup) mutt_mailbox_cleanup(path, &st);