From 8f570a79697901140348ae7021fa318de1f2f3b2 Mon Sep 17 00:00:00 2001 From: Inaky Perez-Gonzalez Date: Tue, 3 Aug 2010 16:50:55 -0700 Subject: sms: struct tx_queue_entry: add a destructor Introduce a destructor function to encapsulate all the release steps for this data type, as more are to be added later. --- src/sms.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/sms.c b/src/sms.c index 35364db8..01596ef4 100644 --- a/src/sms.c +++ b/src/sms.c @@ -406,6 +406,26 @@ static DBusMessage *sms_set_property(DBusConnection *conn, DBusMessage *msg, return __ofono_error_invalid_args(msg); } +/* + * Destroy/release the contents of a 'struct tx_queue_entry' + * + * This releases resources allocated *inside* @entry and @entry + * itself. + */ +static void tx_queue_entry_destroy(struct tx_queue_entry *entry) +{ + if (entry->destroy) + entry->destroy(entry->data); + + g_free(entry->pdus); + g_free(entry); +} + +static void tx_queue_entry_destroy_foreach(gpointer _entry, gpointer unused) +{ + tx_queue_entry_destroy(_entry); +} + static void tx_finished(const struct ofono_error *error, int mr, void *data) { struct ofono_sms *sms = data; @@ -466,11 +486,7 @@ next_q: time(NULL), hs); } - if (entry->destroy) - entry->destroy(entry->data); - - g_free(entry->pdus); - g_free(entry); + tx_queue_entry_destroy(entry); if (g_queue_peek_head(sms->txq)) { DBG("Scheduling next"); @@ -1097,7 +1113,7 @@ static void sms_remove(struct ofono_atom *atom) } if (sms->txq) { - g_queue_foreach(sms->txq, (GFunc)g_free, NULL); + g_queue_foreach(sms->txq, tx_queue_entry_destroy_foreach, NULL); g_queue_free(sms->txq); sms->txq = NULL; } -- cgit v1.2.3