From: Inaky Perez-Gonzalez <[email protected]>
Introduce a destructor function to encapsulate all the release steps
for this data type, as more are to be added later.
---
src/sms.c | 25 +++++++++++++++++++------
1 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/sms.c b/src/sms.c
index 85353ff..5f5df04 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -405,6 +405,23 @@ 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_free(gpointer _entry, gpointer unused)
+{
+ struct tx_queue_entry *entry = _entry;
+
+ if (entry->destroy)
+ entry->destroy(entry->data);
+ g_free(entry->pdus);
+ g_free(entry);
+}
+
static void tx_finished(const struct ofono_error *error, int mr, void *data)
{
struct ofono_sms *sms = data;
@@ -465,11 +482,7 @@ next_q:
time(NULL), hs);
}
- if (entry->destroy)
- entry->destroy(entry->data);
-
- g_free(entry->pdus);
- g_free(entry);
+ tx_queue_entry_destroy_free(entry, NULL);
if (g_queue_peek_head(sms->txq)) {
DBG("Scheduling next");
@@ -1129,7 +1142,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_free, NULL);
g_queue_free(sms->txq);
sms->txq = NULL;
}
--
1.6.6.1
_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono