diff options
author | Vinicius Costa Gomes <vinicius.gomes@openbossa.org> | 2010-08-10 18:01:45 -0300 |
---|---|---|
committer | Vinicius Costa Gomes <vinicius.gomes@openbossa.org> | 2010-08-11 13:54:08 -0300 |
commit | 97a1889bac951c6ff9746d76a763b2ae9ef75f61 (patch) | |
tree | 106f7735797d88b7b328766f24df8fcf9e00f8ec /attrib/gattrib.c | |
parent | f01213d0258289bb8eb89ca137a452c7c88bdbc5 (diff) | |
download | bluez-97a1889bac951c6ff9746d76a763b2ae9ef75f61.tar.gz |
Fix memory leaks on g_attrib_unref()
We must clean up the event list and the command queue when we destroy
GAttrib, it could be that something is still there.
Diffstat (limited to 'attrib/gattrib.c')
-rw-r--r-- | attrib/gattrib.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/attrib/gattrib.c b/attrib/gattrib.c index eef13d9ae..d2276c8e2 100644 --- a/attrib/gattrib.c +++ b/attrib/gattrib.c @@ -140,15 +140,41 @@ GAttrib *g_attrib_ref(GAttrib *attrib) return attrib; } +static void command_destroy(struct command *cmd) +{ + if (cmd->notify) + cmd->notify(cmd->user_data); + + g_free(cmd->pdu); + g_free(cmd); +} + +static void event_destroy(struct event *evt) +{ + if (evt->notify) + evt->notify(evt->user_data); + + g_free(evt); +} + void g_attrib_unref(GAttrib *attrib) { + GSList *l; + struct command *c; + if (!attrib) return; if (g_atomic_int_dec_and_test(&attrib->refs) == FALSE) return; - g_queue_free(attrib->queue); + while ((c = g_queue_pop_head(attrib->queue))) + command_destroy(c); + + for (l = attrib->events; l; l = l->next) + event_destroy(l->data); + + g_slist_free(attrib->events); if (attrib->read_watch > 0) g_source_remove(attrib->read_watch); @@ -168,15 +194,6 @@ static void destroy_receiver(gpointer data) attrib->read_watch = 0; } -static void command_destroy(struct command *cmd) -{ - if (cmd->notify) - cmd->notify(cmd->user_data); - - g_free(cmd->pdu); - g_free(cmd); -} - static void wake_up_sender(struct _GAttrib *attrib); static gboolean received_data(GIOChannel *io, GIOCondition cond, gpointer data) |