From: Richard Russon Date: Sat, 22 Dec 2018 20:47:49 +0000 (+0000) Subject: light tidying X-Git-Tag: 2019-10-25~419 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2d81dc2e2bc5c2da1df9098e4fee5a528290e553;p=neomutt light tidying --- diff --git a/account.c b/account.c index fabae266f..7b1fd4894 100644 --- a/account.c +++ b/account.c @@ -64,7 +64,7 @@ void account_remove_mailbox(struct Account *a, struct Mailbox *m) if (STAILQ_EMPTY(&a->mailboxes)) { TAILQ_REMOVE(&AllAccounts, a, entries); - if (a->adata) + if (a->free_adata) a->free_adata(&a->adata); FREE(&a); } diff --git a/bcache.c b/bcache.c index a483d2a0e..6d7a5f043 100644 --- a/bcache.c +++ b/bcache.c @@ -133,22 +133,18 @@ static int mutt_bcache_move(struct BodyCache *bcache, const char *id, const char */ struct BodyCache *mutt_bcache_open(struct ConnAccount *account, const char *mailbox) { - struct BodyCache *bcache = NULL; - if (!account) - goto bail; + return NULL; - bcache = mutt_mem_calloc(1, sizeof(struct BodyCache)); + struct BodyCache *bcache = mutt_mem_calloc(1, sizeof(struct BodyCache)); if (bcache_path(account, mailbox, bcache->path, sizeof(bcache->path)) < 0) - goto bail; - bcache->pathlen = mutt_str_strlen(bcache->path); + { + FREE(&bcache); + return NULL; + } + bcache->pathlen = mutt_str_strlen(bcache->path); return bcache; - -bail: - if (bcache) - FREE(&bcache); - return NULL; } /** diff --git a/conn/sasl.c b/conn/sasl.c index edd65edfc..684c13311 100644 --- a/conn/sasl.c +++ b/conn/sasl.c @@ -144,7 +144,7 @@ static int iptostring(const struct sockaddr *addr, socklen_t addrlen, char *out, NI_WITHSCOPEID | #endif NI_NUMERICSERV); - if (ret) + if (ret != 0) return getnameinfo_err(ret); if (outlen < strlen(hbuf) + strlen(pbuf) + 2) diff --git a/conn/socket.c b/conn/socket.c index 6cb2983a4..c3d643c2d 100644 --- a/conn/socket.c +++ b/conn/socket.c @@ -106,6 +106,9 @@ int mutt_socket_open(struct Connection *conn) */ int mutt_socket_close(struct Connection *conn) { + if (!conn) + return 0; + int rc = -1; if (conn->fd < 0) diff --git a/edit.c b/edit.c index b2fc3f070..bc2dd6549 100644 --- a/edit.c +++ b/edit.c @@ -192,8 +192,7 @@ static void be_free_memory(char **buf, int buflen) { while (buflen-- > 0) FREE(&buf[buflen]); - if (buf) - FREE(&buf); + FREE(&buf); } /** diff --git a/editmsg.c b/editmsg.c index c49d12af3..e6b1c7956 100644 --- a/editmsg.c +++ b/editmsg.c @@ -238,8 +238,7 @@ static int edit_or_view_one_message(bool edit, struct Mailbox *m, struct Email * mx_mbox_close(&tmpctx, NULL); bail: - if (fp) - mutt_file_fclose(&fp); + mutt_file_fclose(&fp); if (rc >= 0) unlink(tmp); diff --git a/email/body.c b/email/body.c index 7628f73aa..f4e05064d 100644 --- a/email/body.c +++ b/email/body.c @@ -55,6 +55,9 @@ struct Body *mutt_body_new(void) */ void mutt_body_free(struct Body **p) { + if (!p) + return; + struct Body *a = *p, *b = NULL; while (a) @@ -87,9 +90,7 @@ void mutt_body_free(struct Body **p) mutt_email_free(&b->email); } - if (b->parts) - mutt_body_free(&b->parts); - + mutt_body_free(&b->parts); FREE(&b); } diff --git a/main.c b/main.c index de6ad1379..fe1ec3294 100644 --- a/main.c +++ b/main.c @@ -1022,8 +1022,7 @@ int main(int argc, char *argv[], char *envp[]) else bodyfile = tempfile; - if (fin) - mutt_file_fclose(&fin); + mutt_file_fclose(&fin); } FREE(&bodytext); @@ -1214,8 +1213,7 @@ int main(int argc, char *argv[], char *envp[]) mutt_sb_set_open_mailbox(); #endif mutt_index_menu(); - if (Context) - mutt_context_free(&Context); + mutt_context_free(&Context); } #ifdef USE_IMAP imap_logout_all(); diff --git a/mutt/file.c b/mutt/file.c index ed82932d8..0199f5d5e 100644 --- a/mutt/file.c +++ b/mutt/file.c @@ -148,11 +148,10 @@ static int put_file_in_place(const char *path, const char *safe_file, const char */ int mutt_file_fclose(FILE **f) { - int r = 0; - - if (*f) - r = fclose(*f); + if (!f || !*f) + return 0; + int r = fclose(*f); *f = NULL; return r; } diff --git a/mutt_attach.c b/mutt_attach.c index c2f3e5bb7..f6387aa5c 100644 --- a/mutt_attach.c +++ b/mutt_attach.c @@ -96,10 +96,8 @@ int mutt_get_tmp_attachment(struct Body *a) else mutt_perror(fpin ? tempfile : a->filename); - if (fpin) - mutt_file_fclose(&fpin); - if (fpout) - mutt_file_fclose(&fpout); + mutt_file_fclose(&fpin); + mutt_file_fclose(&fpout); return a->unlink ? 0 : -1; } diff --git a/ncrypt/pgplib.c b/ncrypt/pgplib.c index a1970f5c3..1dea5465f 100644 --- a/ncrypt/pgplib.c +++ b/ncrypt/pgplib.c @@ -161,12 +161,10 @@ struct PgpUid *pgp_copy_uids(struct PgpUid *up, struct PgpKeyInfo *parent) */ static void free_key(struct PgpKeyInfo **kpp) { - struct PgpKeyInfo *kp = NULL; - if (!kpp || !*kpp) return; - kp = *kpp; + struct PgpKeyInfo *kp = *kpp; pgp_free_uid(&kp->address); FREE(&kp->keyid); @@ -237,9 +235,8 @@ void pgp_free_key(struct PgpKeyInfo **kpp) r = q->next; free_key(&q); } - if (p->parent) - free_key(&p->parent); + free_key(&p->parent); free_key(&p); } diff --git a/nntp/newsrc.c b/nntp/newsrc.c index 20a627254..314a3fa99 100644 --- a/nntp/newsrc.c +++ b/nntp/newsrc.c @@ -434,8 +434,8 @@ static int update_file(char *filename, char *buf) rc = 0; break; } - if (fp) - mutt_file_fclose(&fp); + mutt_file_fclose(&fp); + if (*tmpfile) unlink(tmpfile); return rc; diff --git a/nntp/nntp.c b/nntp/nntp.c index daaaca4d6..dfc2696d1 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -412,8 +412,7 @@ static int nntp_attempt_features(struct NntpAccountData *adata) int cont = 0; size_t buflen = 2 * LONG_STRING, off = 0, b = 0; - if (adata->overview_fmt) - FREE(&adata->overview_fmt); + FREE(&adata->overview_fmt); adata->overview_fmt = mutt_mem_malloc(buflen); while (true) diff --git a/pattern.c b/pattern.c index d25380a95..aa39699c4 100644 --- a/pattern.c +++ b/pattern.c @@ -1336,6 +1336,9 @@ static /* const */ char *find_matching_paren(/* const */ char *s) */ void mutt_pattern_free(struct Pattern **pat) { + if (!pat || !*pat) + return; + struct Pattern *tmp = NULL; while (*pat) @@ -1355,8 +1358,7 @@ void mutt_pattern_free(struct Pattern **pat) FREE(&tmp->p.regex); } - if (tmp->child) - mutt_pattern_free(&tmp->child); + mutt_pattern_free(&tmp->child); FREE(&tmp); } } @@ -2430,8 +2432,7 @@ int mutt_pattern_func(int op, char *prompt) { /* drop previous limit pattern */ FREE(&Context->pattern); - if (Context->limit_pattern) - mutt_pattern_free(&Context->limit_pattern); + mutt_pattern_free(&Context->limit_pattern); if (Context->mailbox->msg_count && !Context->mailbox->vcount) mutt_error(_("No messages matched criteria")); diff --git a/rfc1524.c b/rfc1524.c index 76c58b733..eeeaf43a2 100644 --- a/rfc1524.c +++ b/rfc1524.c @@ -410,6 +410,9 @@ struct Rfc1524MailcapEntry *rfc1524_new_entry(void) */ void rfc1524_free_entry(struct Rfc1524MailcapEntry **entry) { + if (!entry || !*entry) + return; + struct Rfc1524MailcapEntry *p = *entry; FREE(&p->command); diff --git a/sendlib.c b/sendlib.c index f08eba539..93a14f2e1 100644 --- a/sendlib.c +++ b/sendlib.c @@ -2578,8 +2578,7 @@ static int send_msg(const char *path, char **args, const char *msg, char **tempf else if (pid == -1) { unlink(msg); - if (tempfile) - FREE(tempfile); + FREE(tempfile); _exit(S_ERR); } diff --git a/smtp.c b/smtp.c index 32330aed0..e61b46696 100644 --- a/smtp.c +++ b/smtp.c @@ -815,8 +815,7 @@ int mutt_smtp_send(const struct Address *from, const struct Address *to, rc = 0; } while (false); - if (conn) - mutt_socket_close(conn); + mutt_socket_close(conn); if (rc == SMTP_ERR_READ) mutt_error(_("SMTP session failed: read error"));