While reviewing the code for header->env lifecycle fixes (in the next
commit), I noticed a couple small memory leaks on the error path.
---
 main.c | 2 ++
 mbox.c | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/main.c b/main.c
index c0df633a..7649082a 100644
--- a/main.c
+++ b/main.c
@@ -1154,12 +1154,14 @@ int main(int argc, char **argv, char **environ)
         if (fstat(fileno(fin), &st))
         {
           perror(draftFile);
+          mutt_free_header(&context_hdr);
           goto cleanup_and_exit;
         }
         context_hdr->content->length = st.st_size;
 
         if (mutt_prepare_template(fin, NULL, msg, context_hdr, 0) < 0)
         {
+          mutt_free_header(&context_hdr);
           if (!option(OPTNOCURSES))
           {
             mutt_endwin(NULL);
diff --git a/mbox.c b/mbox.c
index f584337a..224c3bd1 100644
--- a/mbox.c
+++ b/mbox.c
@@ -153,7 +153,8 @@ int mmdf_parse_mailbox(CONTEXT *ctx)
 
       if (fgets(buf, sizeof(buf) - 1, ctx->fp) == NULL)
       {
-        /* TODO: memory leak??? */
+        mutt_free_header(&hdr);
+        ctx->hdrs[ctx->msgcount] = NULL;
         muttdbg(1, "unexpected EOF");
         break;
       }
@@ -164,6 +165,8 @@ int mmdf_parse_mailbox(CONTEXT *ctx)
       {
         if (fseeko(ctx->fp, loc, SEEK_SET) != 0)
         {
+          mutt_free_header(&hdr);
+          ctx->hdrs[ctx->msgcount] = NULL;
           muttdbg(1, "fseek() failed");
           mutt_error _("Mailbox is corrupt!");
           return (-1);
-- 
2.55.0

Reply via email to