From: Richard Russon Date: Thu, 13 Sep 2018 22:17:02 +0000 (+0100) Subject: change free functions to use void** X-Git-Tag: 2019-10-25~648^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b222db7a922a134ca2bac66628d211d48133cae4;p=neomutt change free functions to use void** --- diff --git a/mailbox.c b/mailbox.c index c4de1b4ac..cc6276ac2 100644 --- a/mailbox.c +++ b/mailbox.c @@ -205,10 +205,8 @@ void mailbox_free(struct Mailbox **mailbox) return; FREE(&(*mailbox)->desc); - if ((*mailbox)->free_data) - (*mailbox)->free_data((*mailbox)->data); - (*mailbox)->data = NULL; - + if ((*mailbox)->data && (*mailbox)->free_data) + (*mailbox)->free_data(&(*mailbox)->data); FREE(mailbox); } diff --git a/mailbox.h b/mailbox.h index 22efaa435..37165d930 100644 --- a/mailbox.h +++ b/mailbox.h @@ -99,8 +99,8 @@ struct Mailbox struct timespec last_visited; /**< time of last exit from this mailbox */ struct timespec stats_last_checked; /**< mtime of mailbox the last time stats where checked. */ - void *data; /**< driver specific data */ - void (*free_data)(void *); /**< driver-specific data free function */ + void *data; /**< driver specific data */ + void (*free_data)(void **); /**< driver-specific data free function */ const struct MxOps *mx_ops; bool changed : 1; /**< mailbox has been modified */ diff --git a/mbox/mbox.c b/mbox/mbox.c index 4cbe7e918..0f79abca1 100644 --- a/mbox/mbox.c +++ b/mbox/mbox.c @@ -91,12 +91,12 @@ static struct MboxData *new_mboxdata(void) * free_mboxdata - Free data attached to the Mailbox * @param data Private mailbox data */ -static void free_mboxdata(void *data) +static void free_mboxdata(void **data) { - if (!data) + if (!data || !*data) return; - struct MboxData *m = data; + struct MboxData *m = *data; mutt_file_fclose(&m->fp); } diff --git a/notmuch/mutt_notmuch.c b/notmuch/mutt_notmuch.c index aa1b01ec0..30217dbb8 100644 --- a/notmuch/mutt_notmuch.c +++ b/notmuch/mutt_notmuch.c @@ -177,14 +177,14 @@ static struct NmEmailData *new_emaildata(void) * the database. This function will close the database, free the resources and * the struct itself. */ -static void free_mboxdata(void *data) +static void free_mboxdata(void **data) { - if (!data) + if (!data || !*data) return; mutt_debug(1, "nm: freeing context data %p\n", data); - struct NmMboxData *mdata = data; + struct NmMboxData *mdata = *data; if (mdata->db) #ifdef NOTMUCH_API_3 @@ -197,7 +197,7 @@ static void free_mboxdata(void *data) url_free(&mdata->db_url); FREE(&mdata->db_url_holder); FREE(&mdata->db_query); - FREE(&mdata); + FREE(data); } /** diff --git a/pop/pop.c b/pop/pop.c index bbcb20538..5a452b546 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -129,9 +129,12 @@ static struct PopEmailData *new_emaildata(const char *uid) * the database. This function will close the database, free the resources and * the struct itself. */ -static void free_mboxdata(void *data) +static void free_mboxdata(void **data) { - FREE(&data); + if (!data || !*data) + return; + + FREE(data); } /**