diff options
author | Luiz Augusto von Dentz <luiz.dentz@openbossa.org> | 2009-04-28 17:37:32 -0300 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2009-04-30 00:35:41 +0300 |
commit | e8610fcbe0341a4879b8230d97cd27f5f8cf9f58 (patch) | |
tree | a65fcf5981cf025a1233e1bcfefb42e00b82cf8a /common/glib-helper.c | |
parent | 79ab8a8912bb6e128c6bf1ada7831cf7cc6e740b (diff) |
Fix bt_cancel_discovery to not call callback.
bt_cancel_discovery when disconnecting async and calling the callback
which cause crashes if the user data is free'd in between.
Diffstat (limited to 'common/glib-helper.c')
-rw-r--r-- | common/glib-helper.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/common/glib-helper.c b/common/glib-helper.c index e892a893..bdee0988 100644 --- a/common/glib-helper.c +++ b/common/glib-helper.c @@ -147,6 +147,7 @@ struct search_context { bt_destroy_t destroy; gpointer user_data; uuid_t uuid; + guint io_id; }; static GSList *context_list = NULL; @@ -252,6 +253,7 @@ static gboolean connect_watch(GIOChannel *chan, GIOCondition cond, gpointer user int sk, err = 0; sk = g_io_channel_unix_get_fd(chan); + ctxt->io_id = 0; len = sizeof(err); if (getsockopt(sk, SOL_SOCKET, SO_ERROR, &err, &len) < 0) { @@ -322,8 +324,9 @@ static int create_search_context(struct search_context **ctxt, (*ctxt)->uuid = *uuid; chan = g_io_channel_unix_new(sdp_get_socket(s)); - g_io_add_watch(chan, G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL, - connect_watch, *ctxt); + (*ctxt)->io_id = g_io_add_watch(chan, + G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL, + connect_watch, *ctxt); g_io_channel_unref(chan); return 0; @@ -388,7 +391,12 @@ int bt_cancel_discovery(const bdaddr_t *src, const bdaddr_t *dst) if (!ctxt->session) return -ENOTCONN; - close(ctxt->session->sock); + if (ctxt->io_id) + g_source_remove(ctxt->io_id); + + sdp_close(ctxt->session); + + search_context_cleanup(ctxt); return 0; } |