From: Pietro Cerutti Date: Fri, 10 Feb 2017 17:14:13 +0000 (+0000) Subject: Fix latest Coverity issues (#387) X-Git-Tag: neomutt-20170225~30 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7adf125fafc3b8b387fa767a535ddfe1fa533daa;p=neomutt Fix latest Coverity issues (#387) * Fix two use-before-check bugs Closes #386 * Fix memory leak Issue #386 * Treat a NULL b->subtype as a wildcard (*) Issue #386 * Move assignment out of conditional Closes #386 * Move assignment out of conditional (2) Closes #386 --- diff --git a/imap/util.c b/imap/util.c index 35a472e5d..fa4c974ff 100644 --- a/imap/util.c +++ b/imap/util.c @@ -909,15 +909,23 @@ int imap_wait_keepalive (pid_t pid) void imap_allow_reopen (CONTEXT *ctx) { - IMAP_DATA* idata = ctx->data; - if (ctx && ctx->magic == MUTT_IMAP && idata->ctx == ctx) + IMAP_DATA *idata; + if (!ctx || !ctx->data || ctx->magic != MUTT_IMAP) + return; + + idata = ctx->data; + if (idata->ctx == ctx) idata->reopen |= IMAP_REOPEN_ALLOW; } void imap_disallow_reopen (CONTEXT *ctx) { - IMAP_DATA* idata = ctx->data; - if (ctx && ctx->magic == MUTT_IMAP && idata->ctx == ctx) + IMAP_DATA *idata; + if (!ctx || !ctx->data || ctx->magic != MUTT_IMAP) + return; + + idata = ctx->data; + if (idata->ctx == ctx) idata->reopen &= ~IMAP_REOPEN_ALLOW; } diff --git a/init.c b/init.c index 26b292d90..8a5f9a898 100644 --- a/init.c +++ b/init.c @@ -506,11 +506,14 @@ static int add_to_replace_list (REPLACE_LIST **list, const char *pat, const char { t = mutt_new_replace_list(); t->rx = rx; + rx = NULL; if (last) last->next = t; else *list = t; } + else + mutt_free_regexp(&rx); /* Now t is the REPLACE_LIST* that we want to modify. It is prepared. */ t->template = safe_strdup(templ); diff --git a/parse.c b/parse.c index bf47b1fff..da006af9d 100644 --- a/parse.c +++ b/parse.c @@ -1565,9 +1565,10 @@ static int count_body_parts_check(LIST **checklist, BODY *b, int dflt) a = (ATTACH_MATCH *)type->data; mutt_debug (5, "cbpc: %s %d/%s ?? %s/%s [%d]... ", dflt ? "[OK] " : "[EXCL] ", - b->type, b->subtype, a->major, a->minor, a->major_int); + b->type, b->subtype ? b->subtype : "*", + a->major, a->minor, a->major_int); if ((a->major_int == TYPEANY || a->major_int == b->type) && - !regexec(&a->minor_rx, b->subtype, 0, NULL, 0)) + (!b->subtype || !regexec(&a->minor_rx, b->subtype, 0, NULL, 0))) { mutt_debug (5, "yes\n"); return 1;