]> granicus.if.org Git - neomutt/commitdiff
Prevent ctx->fp from being closed twice in the event of an error.
authorKevin McCarthy <kevin@8t8.us>
Wed, 16 Mar 2016 01:04:26 +0000 (18:04 -0700)
committerKevin McCarthy <kevin@8t8.us>
Wed, 16 Mar 2016 01:04:26 +0000 (18:04 -0700)
The previous patch from Vincent exposed a crash if ftruncate() fails
in mbox_sync_mailbox().  Change fclose() to safe_fclose(), to avoid it
being called twice.

mbox.c

diff --git a/mbox.c b/mbox.c
index 870da6aaa8fc49d9abff26891aecd634e8d8237c..95cba6547241da11783c266259504e834171c4c5 100644 (file)
--- a/mbox.c
+++ b/mbox.c
@@ -980,7 +980,7 @@ int mbox_sync_mailbox (CONTEXT *ctx, int *index_hint)
   fp = NULL;
   mbox_unlock_mailbox (ctx);
 
-  if (fclose (ctx->fp) != 0 || i == -1)
+  if (safe_fclose (&ctx->fp) != 0 || i == -1)
   {
     /* error occurred while writing the mailbox back, so keep the temp copy
      * around