From ce422cb33e07d626c8b606418f8195724fa11248 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Tue, 16 Jul 2019 20:44:32 +0100 Subject: [PATCH] unify private data free functions --- core/account.c | 5 ++--- core/mailbox.c | 6 ++++-- core/neomutt.c | 2 +- email/email.c | 31 ++++++++++++++++++------------- email/email.h | 2 +- mutt/hash.c | 14 +++++++------- mutt/hash.h | 12 ++++++------ 7 files changed, 39 insertions(+), 33 deletions(-) diff --git a/core/account.c b/core/account.c index e8ba4399f..e1dc7e7de 100644 --- a/core/account.c +++ b/core/account.c @@ -117,13 +117,12 @@ void account_free(struct Account **ptr) return; struct Account *a = *ptr; - account_mailbox_remove(a, NULL); + notify_free(&a->notify); if (a->free_adata) a->free_adata(&a->adata); - notify_free(&a->notify); - // account_free_config(a); + account_mailbox_remove(a, NULL); cs_subset_free(&a->sub); FREE(&a->name); diff --git a/core/mailbox.c b/core/mailbox.c index 6e427c864..07edf6fd0 100644 --- a/core/mailbox.c +++ b/core/mailbox.c @@ -62,11 +62,13 @@ void mailbox_free(struct Mailbox **ptr) mailbox_changed(m, MBN_CLOSED); notify_free(&m->notify); - mutt_buffer_free(&m->pathbuf); - FREE(&m->name); if (m->mdata && m->free_mdata) m->free_mdata(&m->mdata); + + mutt_buffer_free(&m->pathbuf); + FREE(&m->name); FREE(&m->realpath); + FREE(ptr); } diff --git a/core/neomutt.c b/core/neomutt.c index 9369e7bee..d6c919a3d 100644 --- a/core/neomutt.c +++ b/core/neomutt.c @@ -66,9 +66,9 @@ void neomutt_free(struct NeoMutt **ptr) return; struct NeoMutt *n = *ptr; + notify_free(&n->notify); neomutt_account_remove(n, NULL); - notify_free(&n->notify); cs_subset_free(&n->sub); FREE(ptr); diff --git a/email/email.c b/email/email.c index 4e83d97da..8d44603be 100644 --- a/email/email.c +++ b/email/email.c @@ -36,24 +36,29 @@ /** * email_free - Free an Email - * @param[out] e Email to free + * @param[out] ptr Email to free */ -void email_free(struct Email **e) +void email_free(struct Email **ptr) { - if (!e || !*e) + if (!ptr || !*ptr) return; - mutt_env_free(&(*e)->env); - mutt_body_free(&(*e)->content); - FREE(&(*e)->maildir_flags); - FREE(&(*e)->tree); - FREE(&(*e)->path); + + struct Email *e = *ptr; + + if (e->edata && e->free_edata) + e->free_edata(&e->edata); + + mutt_env_free(&e->env); + mutt_body_free(&e->content); + FREE(&e->maildir_flags); + FREE(&e->tree); + FREE(&e->path); #ifdef MIXMASTER - mutt_list_free(&(*e)->chain); + mutt_list_free(&e->chain); #endif - driver_tags_free(&(*e)->tags); - if ((*e)->edata && (*e)->free_edata) - (*e)->free_edata(&(*e)->edata); - FREE(e); + driver_tags_free(&e->tags); + + FREE(ptr); } /** diff --git a/email/email.h b/email/email.h index 0feaa6d6f..095464a1a 100644 --- a/email/email.h +++ b/email/email.h @@ -122,7 +122,7 @@ struct EmailNode STAILQ_HEAD(EmailList, EmailNode); bool email_cmp_strict(const struct Email *e1, const struct Email *e2); -void email_free (struct Email **e); +void email_free (struct Email **ptr); struct Email *email_new (void); size_t email_size (const struct Email *e); diff --git a/mutt/hash.c b/mutt/hash.c index 28607146b..83dbde9ea 100644 --- a/mutt/hash.c +++ b/mutt/hash.c @@ -251,8 +251,8 @@ static void union_hash_delete(struct Hash *table, union HashKey key, const void if (((data == ptr->data) || !data) && (table->cmp_key(ptr->key, key) == 0)) { *last = ptr->next; - if (table->elem_free) - table->elem_free(ptr->type, ptr->data, table->hash_data); + if (table->free_hdata) + table->free_hdata(ptr->type, ptr->data, table->hdata); if (table->strdup_keys) FREE(&ptr->key.strkey); FREE(&ptr); @@ -319,8 +319,8 @@ void mutt_hash_set_destructor(struct Hash *table, hashelem_free_t fn, intptr_t f { if (!table) return; - table->elem_free = fn; - table->hash_data = fn_data; + table->free_hdata = fn; + table->hdata = fn_data; } /** @@ -466,7 +466,7 @@ void mutt_hash_int_delete(struct Hash *table, unsigned int intkey, const void *d } /** - * mutt_hash_free - elem_free a hash table + * mutt_hash_free - free_hdata a hash table * @param[out] ptr Hash Table to be freed */ void mutt_hash_free(struct Hash **ptr) @@ -483,8 +483,8 @@ void mutt_hash_free(struct Hash **ptr) { tmp = elem; elem = elem->next; - if (pptr->elem_free) - pptr->elem_free(tmp->type, tmp->data, pptr->hash_data); + if (pptr->free_hdata) + pptr->free_hdata(tmp->type, tmp->data, pptr->hdata); if (pptr->strdup_keys) FREE(&tmp->key.strkey); FREE(&tmp); diff --git a/mutt/hash.h b/mutt/hash.h index dbd980f28..97a13088d 100644 --- a/mutt/hash.h +++ b/mutt/hash.h @@ -60,14 +60,14 @@ typedef void (*hashelem_free_t)(int type, void *obj, intptr_t data); */ struct Hash { - size_t nelem; ///< Number of elements in the Hash table - bool strdup_keys : 1; ///< if set, the key->strkey is strdup'ed - bool allow_dups : 1; ///< if set, duplicate keys are allowed - struct HashElem **table; ///< Array of Hash keys + size_t nelem; ///< Number of elements in the Hash table + bool strdup_keys : 1; ///< if set, the key->strkey is strdup'ed + bool allow_dups : 1; ///< if set, duplicate keys are allowed + struct HashElem **table; ///< Array of Hash keys size_t (*gen_hash)(union HashKey, size_t); ///< Function to generate hash id from the key int (*cmp_key)(union HashKey, union HashKey); ///< Function to compare two Hash keys - hashelem_free_t elem_free; ///< Function to free a Hash element - intptr_t hash_data; ///< Data to pass to the elem_free() function + intptr_t hdata; ///< Data to pass to the free_hdata() function + hashelem_free_t free_hdata; ///< Function to free a Hash element }; typedef uint8_t HashFlags; ///< Flags for mutt_hash_new(), e.g. #MUTT_HASH_STRCASECMP -- 2.40.0