From b48ed482a9252c9227ae318ff1364b74612e6666 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Sat, 31 Aug 2019 13:22:19 +0100 Subject: [PATCH] unify new/free() functions 1 - Name ends in `_free()` - Take a `**ptr` - Creates a native pointer - Sets pointer to `NULL` Functions changed: - cs_free() - mailcap_entry_free() - mutt_addr_free() - mutt_alias_free() - mutt_alias_new() - mutt_body_free() - mutt_enter_state_free() - mutt_env_free() - mutt_seqset_iterator_free() - nntp_edata_free() - query_free() - remailer_free() - remailer_new() --- address/address.c | 15 ++++++----- address/address.h | 2 +- alias.c | 18 +++++++------ alias.h | 2 +- config/set.c | 14 +++++----- config/set.h | 2 +- email/body.c | 10 +++---- email/body.h | 2 +- email/envelope.c | 65 ++++++++++++++++++++++++--------------------- email/envelope.h | 2 +- enter.c | 12 +++++---- enter_state.h | 2 +- imap/imap_private.h | 2 +- imap/util.c | 10 +++---- mailcap.c | 24 ++++++++--------- mailcap.h | 2 +- nntp/nntp.c | 7 ++--- query.c | 14 +++++----- remailer.c | 30 ++++++++++++--------- 19 files changed, 126 insertions(+), 109 deletions(-) diff --git a/address/address.c b/address/address.c index 473e00d9c..cfaf0ae44 100644 --- a/address/address.c +++ b/address/address.c @@ -434,15 +434,18 @@ int mutt_addrlist_remove(struct AddressList *al, const char *mailbox) /** * mutt_addr_free - Free a single Address - * @param[out] a Address to free + * @param[out] ptr Address to free */ -void mutt_addr_free(struct Address **a) +void mutt_addr_free(struct Address **ptr) { - if (!a || !*a) + if (!ptr || !*ptr) return; - FREE(&(*a)->personal); - FREE(&(*a)->mailbox); - FREE(a); + + struct Address *a = *ptr; + + FREE(&a->personal); + FREE(&a->mailbox); + FREE(ptr); } /** diff --git a/address/address.h b/address/address.h index 61c6d7b72..5bfae6887 100644 --- a/address/address.h +++ b/address/address.h @@ -70,7 +70,7 @@ bool mutt_addr_cmp (const struct Address *a, const struct Addr struct Address *mutt_addr_copy (const struct Address *addr); struct Address *mutt_addr_create (const char *personal, const char *mailbox); const char * mutt_addr_for_display(const struct Address *a); -void mutt_addr_free (struct Address **a); +void mutt_addr_free (struct Address **ptr); struct Address *mutt_addr_new (void); bool mutt_addr_to_intl (struct Address *a); bool mutt_addr_to_local (struct Address *a); diff --git a/alias.c b/alias.c index 639d9861f..56f39ed5c 100644 --- a/alias.c +++ b/alias.c @@ -142,7 +142,7 @@ static void expand_aliases_r(struct AddressList *al, struct ListHead *expn) * * Free the result with mutt_alias_free() */ -struct Alias *mutt_alias_new() +struct Alias *mutt_alias_new(void) { struct Alias *a = mutt_mem_calloc(1, sizeof(struct Alias)); TAILQ_INIT(&a->addr); @@ -737,17 +737,19 @@ bool mutt_addr_is_user(const struct Address *addr) /** * mutt_alias_free - Free an Alias - * @param[out] p Alias to free + * @param[out] ptr Alias to free */ -void mutt_alias_free(struct Alias **p) +void mutt_alias_free(struct Alias **ptr) { - if (!p || !*p) + if (!ptr || !*ptr) return; - mutt_alias_delete_reverse(*p); - FREE(&(*p)->name); - mutt_addrlist_clear(&((*p)->addr)); - FREE(p); + struct Alias *a = *ptr; + + mutt_alias_delete_reverse(a); + FREE(&a->name); + mutt_addrlist_clear(&(a->addr)); + FREE(ptr); } /** diff --git a/alias.h b/alias.h index 768407f93..58cbf0b59 100644 --- a/alias.h +++ b/alias.h @@ -46,7 +46,7 @@ struct Alias TAILQ_HEAD(AliasList, Alias); struct Alias *mutt_alias_new(void); -void mutt_alias_free(struct Alias **p); +void mutt_alias_free(struct Alias **ptr); void mutt_alias_create(struct Envelope *cur, struct AddressList *al); void mutt_aliaslist_free(struct AliasList *a_list); struct AddressList *mutt_alias_lookup(const char *s); diff --git a/config/set.c b/config/set.c index e4c76924a..4c26a15fa 100644 --- a/config/set.c +++ b/config/set.c @@ -193,16 +193,18 @@ void cs_init(struct ConfigSet *cs, size_t size) /** * cs_free - Free a Config Set - * @param[out] cs Config items + * @param[out] ptr Config items */ -void cs_free(struct ConfigSet **cs) +void cs_free(struct ConfigSet **ptr) { - if (!cs || !*cs) + if (!ptr || !*ptr) return; - mutt_hash_free(&(*cs)->hash); - notify_free(&(*cs)->notify); - FREE(cs); + struct ConfigSet *cs = *ptr; + + mutt_hash_free(&cs->hash); + notify_free(&cs->notify); + FREE(ptr); } /** diff --git a/config/set.h b/config/set.h index f0d375e2c..7c3e26e26 100644 --- a/config/set.h +++ b/config/set.h @@ -205,7 +205,7 @@ struct EventConfig struct ConfigSet *cs_new(size_t size); void cs_init(struct ConfigSet *cs, size_t size); -void cs_free(struct ConfigSet **cs); +void cs_free(struct ConfigSet **ptr); struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name); const struct ConfigSetType *cs_get_type_def(const struct ConfigSet *cs, unsigned int type); diff --git a/email/body.c b/email/body.c index 846f54131..de3d2d1aa 100644 --- a/email/body.c +++ b/email/body.c @@ -52,14 +52,14 @@ struct Body *mutt_body_new(void) /** * mutt_body_free - Free a Body - * @param[out] p Body to free + * @param[out] ptr Body to free */ -void mutt_body_free(struct Body **p) +void mutt_body_free(struct Body **ptr) { - if (!p) + if (!ptr) return; - struct Body *a = *p, *b = NULL; + struct Body *a = *ptr, *b = NULL; while (a) { @@ -96,7 +96,7 @@ void mutt_body_free(struct Body **p) FREE(&b); } - *p = NULL; + *ptr = NULL; } /** diff --git a/email/body.h b/email/body.h index 78cab06a5..99500ac6e 100644 --- a/email/body.h +++ b/email/body.h @@ -90,7 +90,7 @@ struct Body }; bool mutt_body_cmp_strict(const struct Body *b1, const struct Body *b2); -void mutt_body_free (struct Body **p); +void mutt_body_free (struct Body **ptr); struct Body *mutt_body_new (void); #endif /* MUTT_EMAIL_BODY_H */ diff --git a/email/envelope.c b/email/envelope.c index e6551471b..b286e428f 100644 --- a/email/envelope.c +++ b/email/envelope.c @@ -82,50 +82,53 @@ void mutt_free_autocrypthdr(struct AutocryptHeader **p) /** * mutt_env_free - Free an Envelope - * @param[out] p Envelope to free + * @param[out] ptr Envelope to free */ -void mutt_env_free(struct Envelope **p) +void mutt_env_free(struct Envelope **ptr) { - if (!p || !*p) + if (!ptr || !*ptr) return; - mutt_addrlist_clear(&(*p)->return_path); - mutt_addrlist_clear(&(*p)->from); - mutt_addrlist_clear(&(*p)->to); - mutt_addrlist_clear(&(*p)->cc); - mutt_addrlist_clear(&(*p)->bcc); - mutt_addrlist_clear(&(*p)->sender); - mutt_addrlist_clear(&(*p)->reply_to); - mutt_addrlist_clear(&(*p)->mail_followup_to); - mutt_addrlist_clear(&(*p)->x_original_to); - FREE(&(*p)->list_post); - FREE(&(*p)->subject); + struct Envelope *env = *ptr; + + mutt_addrlist_clear(&env->return_path); + mutt_addrlist_clear(&env->from); + mutt_addrlist_clear(&env->to); + mutt_addrlist_clear(&env->cc); + mutt_addrlist_clear(&env->bcc); + mutt_addrlist_clear(&env->sender); + mutt_addrlist_clear(&env->reply_to); + mutt_addrlist_clear(&env->mail_followup_to); + mutt_addrlist_clear(&env->x_original_to); + + FREE(&env->list_post); + FREE(&env->subject); /* real_subj is just an offset to subject and shouldn't be freed */ - FREE(&(*p)->disp_subj); - FREE(&(*p)->message_id); - FREE(&(*p)->supersedes); - FREE(&(*p)->date); - FREE(&(*p)->x_label); - FREE(&(*p)->organization); + FREE(&env->disp_subj); + FREE(&env->message_id); + FREE(&env->supersedes); + FREE(&env->date); + FREE(&env->x_label); + FREE(&env->organization); #ifdef USE_NNTP - FREE(&(*p)->newsgroups); - FREE(&(*p)->xref); - FREE(&(*p)->followup_to); - FREE(&(*p)->x_comment_to); + FREE(&env->newsgroups); + FREE(&env->xref); + FREE(&env->followup_to); + FREE(&env->x_comment_to); #endif - mutt_buffer_dealloc(&(*p)->spam); + mutt_buffer_dealloc(&env->spam); - mutt_list_free(&(*p)->references); - mutt_list_free(&(*p)->in_reply_to); - mutt_list_free(&(*p)->userhdrs); + mutt_list_free(&env->references); + mutt_list_free(&env->in_reply_to); + mutt_list_free(&env->userhdrs); #ifdef USE_AUTOCRYPT - mutt_free_autocrypthdr(&(*p)->autocrypt); - mutt_free_autocrypthdr(&(*p)->autocrypt_gossip); + mutt_free_autocrypthdr(&env->autocrypt); + mutt_free_autocrypthdr(&env->autocrypt_gossip); #endif - FREE(p); + FREE(ptr); } /** diff --git a/email/envelope.h b/email/envelope.h index 5d013c096..7b3adac1e 100644 --- a/email/envelope.h +++ b/email/envelope.h @@ -89,7 +89,7 @@ struct Envelope }; bool mutt_env_cmp_strict(const struct Envelope *e1, const struct Envelope *e2); -void mutt_env_free (struct Envelope **p); +void mutt_env_free (struct Envelope **ptr); void mutt_env_merge (struct Envelope *base, struct Envelope **extra); struct Envelope *mutt_env_new (void); int mutt_env_to_intl (struct Envelope *env, const char **tag, char **err); diff --git a/enter.c b/enter.c index 373fccc9f..b4d02f31f 100644 --- a/enter.c +++ b/enter.c @@ -818,13 +818,15 @@ bye: /** * mutt_enter_state_free - Free an EnterState - * @param[out] esp EnterState to free + * @param[out] ptr EnterState to free */ -void mutt_enter_state_free(struct EnterState **esp) +void mutt_enter_state_free(struct EnterState **ptr) { - if (!esp || !*esp) + if (!ptr || !*ptr) return; - FREE(&(*esp)->wbuf); - FREE(esp); + struct EnterState *es = *ptr; + + FREE(&es->wbuf); + FREE(ptr); } diff --git a/enter_state.h b/enter_state.h index f140998ce..14586a2da 100644 --- a/enter_state.h +++ b/enter_state.h @@ -38,7 +38,7 @@ struct EnterState int tabs; }; -void mutt_enter_state_free(struct EnterState **esp); +void mutt_enter_state_free(struct EnterState **ptr); struct EnterState *mutt_enter_state_new(void); #endif /* MUTT_ENTER_STATE_H */ diff --git a/imap/imap_private.h b/imap/imap_private.h index b702ee651..a18722caf 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -329,7 +329,7 @@ void imap_munge_mbox_name(bool unicode, char *dest, size_t dlen, const char *src void imap_unmunge_mbox_name(bool unicode, char *s); struct SeqsetIterator *mutt_seqset_iterator_new(const char *seqset); int mutt_seqset_iterator_next(struct SeqsetIterator *iter, unsigned int *next); -void mutt_seqset_iterator_free(struct SeqsetIterator **p_iter); +void mutt_seqset_iterator_free(struct SeqsetIterator **ptr); bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2); void imap_get_parent(const char *mbox, char delim, char *buf, size_t buflen); diff --git a/imap/util.c b/imap/util.c index 611bc704a..bc684bfd3 100644 --- a/imap/util.c +++ b/imap/util.c @@ -1258,14 +1258,14 @@ int mutt_seqset_iterator_next(struct SeqsetIterator *iter, unsigned int *next) /** * mutt_seqset_iterator_free - Free a Sequence Set Iterator - * @param[out] p_iter Iterator to free + * @param[out] ptr Iterator to free */ -void mutt_seqset_iterator_free(struct SeqsetIterator **p_iter) +void mutt_seqset_iterator_free(struct SeqsetIterator **ptr) { - if (!p_iter || !*p_iter) + if (!ptr || !*ptr) return; - struct SeqsetIterator *iter = *p_iter; + struct SeqsetIterator *iter = *ptr; FREE(&iter->full_seqset); - FREE(p_iter); + FREE(ptr); } diff --git a/mailcap.c b/mailcap.c index c55f7bb50..062b5d4d1 100644 --- a/mailcap.c +++ b/mailcap.c @@ -432,23 +432,23 @@ struct MailcapEntry *mailcap_entry_new(void) /** * mailcap_entry_free - Deallocate an struct MailcapEntry - * @param[out] entry MailcapEntry to deallocate + * @param[out] ptr MailcapEntry to deallocate */ -void mailcap_entry_free(struct MailcapEntry **entry) +void mailcap_entry_free(struct MailcapEntry **ptr) { - if (!entry || !*entry) + if (!ptr || !*ptr) return; - struct MailcapEntry *p = *entry; + struct MailcapEntry *me = *ptr; - FREE(&p->command); - FREE(&p->testcommand); - FREE(&p->composecommand); - FREE(&p->composetypecommand); - FREE(&p->editcommand); - FREE(&p->printcommand); - FREE(&p->nametemplate); - FREE(entry); + FREE(&me->command); + FREE(&me->testcommand); + FREE(&me->composecommand); + FREE(&me->composetypecommand); + FREE(&me->editcommand); + FREE(&me->printcommand); + FREE(&me->nametemplate); + FREE(ptr); } /** diff --git a/mailcap.h b/mailcap.h index 7de89eacf..d8fc880be 100644 --- a/mailcap.h +++ b/mailcap.h @@ -61,7 +61,7 @@ enum MailcapLookup MUTT_MC_AUTOVIEW, ///< Mailcap autoview field }; -void mailcap_entry_free(struct MailcapEntry **entry); +void mailcap_entry_free(struct MailcapEntry **ptr); struct MailcapEntry *mailcap_entry_new(void); int mailcap_expand_command(struct Body *a, const char *filename, const char *type, struct Buffer *command); void mailcap_expand_filename(const char *nametemplate, const char *oldfile, struct Buffer *newfile); diff --git a/nntp/nntp.c b/nntp/nntp.c index dbba5f865..1f7574b3e 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -191,11 +191,12 @@ void nntp_mdata_free(void **ptr) /** * nntp_edata_free - Free data attached to an Email - * @param[out] data Email data + * @param[out] ptr Email data */ -static void nntp_edata_free(void **data) +static void nntp_edata_free(void **ptr) { - FREE(data); + // struct NntpEmailData *edata = *ptr; + FREE(ptr); } /** diff --git a/query.c b/query.c index 46d5677e7..f9d439cba 100644 --- a/query.c +++ b/query.c @@ -122,16 +122,16 @@ static struct Query *query_new(void) } /** - * free_query - Free a Query + * query_free - Free a Query * @param[out] query Query to free */ -static void free_query(struct Query **query) +static void query_free(struct Query **query) { - struct Query *p = NULL; - if (!query) return; + struct Query *p = NULL; + while (*query) { p = *query; @@ -405,7 +405,7 @@ static void query_menu(char *buf, size_t buflen, struct Query *results, bool ret if (op == OP_QUERY) { - free_query(&results); + query_free(&results); results = newresults; FREE(&query_table); } @@ -597,7 +597,7 @@ static void query_menu(char *buf, size_t buflen, struct Query *results, bool ret } } - free_query(&results); + query_free(&results); FREE(&query_table); mutt_menu_pop_current(menu); mutt_menu_free(&menu); @@ -631,7 +631,7 @@ int mutt_query_complete(char *buf, size_t buflen) buf[0] = '\0'; mutt_addrlist_write(buf, buflen, &al, false); mutt_addrlist_clear(&al); - free_query(&results); + query_free(&results); mutt_clear_error(); } return 0; diff --git a/remailer.c b/remailer.c index 3133c0641..eb4d8f12c 100644 --- a/remailer.c +++ b/remailer.c @@ -132,25 +132,29 @@ static void mix_add_entry(struct Remailer ***type2_list, struct Remailer *entry, } /** - * mix_new_remailer - Create a new Remailer + * remailer_new - Create a new Remailer * @retval ptr Newly allocated Remailer */ -static struct Remailer *mix_new_remailer(void) +static struct Remailer *remailer_new(void) { return mutt_mem_calloc(1, sizeof(struct Remailer)); } /** - * mix_free_remailer - Free a Remailer - * @param[out] r Remailer to free + * remailer_free - Free a Remailer + * @param[out] ptr Remailer to free */ -static void mix_free_remailer(struct Remailer **r) +static void remailer_free(struct Remailer **ptr) { - FREE(&(*r)->shortname); - FREE(&(*r)->addr); - FREE(&(*r)->ver); + if (!ptr || !*ptr) + return; + + struct Remailer *r = *ptr; - FREE(r); + FREE(&r->shortname); + FREE(&r->addr); + FREE(&r->ver); + FREE(ptr); } /** @@ -191,13 +195,13 @@ static struct Remailer **mix_type2_list(size_t *l) /* first, generate the "random" remailer */ - p = mix_new_remailer(); + p = remailer_new(); p->shortname = mutt_str_strdup(_("")); mix_add_entry(&type2_list, p, &slots, &used); while (fgets(line, sizeof(line), fp)) { - p = mix_new_remailer(); + p = remailer_new(); t = strtok(line, " \t\n"); if (!t) @@ -231,7 +235,7 @@ static struct Remailer **mix_type2_list(size_t *l) continue; problem: - mix_free_remailer(&p); + remailer_free(&p); } *l = used; @@ -253,7 +257,7 @@ static void mix_free_type2_list(struct Remailer ***ttlp) struct Remailer **type2_list = *ttlp; for (int i = 0; type2_list[i]; i++) - mix_free_remailer(&type2_list[i]); + remailer_free(&type2_list[i]); FREE(type2_list); } -- 2.40.0