From: Manuel Naranjo <manuel@aircable.net>
To: BlueZ <linux-bluetooth@vger.kernel.org>
Subject: [PATCH][RFC] Fix SDP resolving segfault
Date: Tue, 20 Jul 2010 20:33:33 -0300 [thread overview]
Message-ID: <4C46324D.5070800@aircable.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 162 bytes --]
Guys,
I think this patch fixes the weird segfault I had been experiencing for
the last few months.
Manuel
Signed-off-by: Manuel Naranjo<manuel@aircable.net>
[-- Attachment #2: 0001-Possible-fix-for-BlueZ-SDP-segfaults.patch --]
[-- Type: text/plain, Size: 2763 bytes --]
>From a292f1df55ace6d4c7e4e91edf833b7e4f07e5a7 Mon Sep 17 00:00:00 2001
From: Manuel Francisco Naranjo <manuel@aircable.net>
Date: Tue, 20 Jul 2010 20:12:56 -0300
Subject: [PATCH] Possible fix for BlueZ SDP segfaults
modified: src/glib-helper.c
Sometimes when you do a DiscoverServices through DBUS and the device goes out of
range then BlueZ will end with a SegFault. I've traced it, and it seems like
connect_watch is been triggered, it gets into the failed tag and when it does the
callback as the btd_device has been released before, the callback triggers the
segfault.
This patch seems to fix the problem, not sure if this is the best way, or the right
one at all. Maybe the problem is that btd_device has no direct reference to the
search_context and then when btd_device is released there's no direct search_context
release (this happens through the function bt_cancel_discovery, but I have a feeling
this approach is actually failing in some cases).
---
src/glib-helper.c | 18 ++++++++++++------
1 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/glib-helper.c b/src/glib-helper.c
index 41f5e3c..fef0d41 100644
--- a/src/glib-helper.c
+++ b/src/glib-helper.c
@@ -156,8 +156,10 @@ static void search_context_cleanup(struct search_context *ctxt)
{
context_list = g_slist_remove(context_list, ctxt);
- if (ctxt->destroy)
+ if (ctxt->destroy){
ctxt->destroy(ctxt->user_data);
+ ctxt->user_data = NULL;
+ }
g_free(ctxt);
}
@@ -206,7 +208,7 @@ static void search_completed_cb(uint8_t type, uint16_t status,
done:
cache_sdp_session(&ctxt->src, &ctxt->dst, ctxt->session);
- if (ctxt->cb)
+ if (ctxt->cb && ctxt->user_data)
ctxt->cb(recs, err, ctxt->user_data);
if (recs)
@@ -236,7 +238,7 @@ failed:
sdp_close(ctxt->session);
ctxt->session = NULL;
- if (ctxt->cb)
+ if (ctxt->cb && ctxt->user_data)
ctxt->cb(NULL, err, ctxt->user_data);
search_context_cleanup(ctxt);
@@ -254,6 +256,8 @@ static gboolean connect_watch(GIOChannel *chan, GIOCondition cond, gpointer user
int sk, err = 0;
sk = g_io_channel_unix_get_fd(chan);
+ if (ctxt->io_id)
+ g_source_remove(ctxt->io_id);
ctxt->io_id = 0;
len = sizeof(err);
@@ -293,7 +297,7 @@ failed:
sdp_close(ctxt->session);
ctxt->session = NULL;
- if (ctxt->cb)
+ if (ctxt->cb && ctxt->user_data)
ctxt->cb(NULL, -err, ctxt->user_data);
search_context_cleanup(ctxt);
@@ -391,11 +395,13 @@ int bt_cancel_discovery(const bdaddr_t *src, const bdaddr_t *dst)
return -ENODATA;
ctxt = match->data;
- if (!ctxt->session)
- return -ENOTCONN;
if (ctxt->io_id)
g_source_remove(ctxt->io_id);
+ ctxt->io_id = 0;
+
+ if (!ctxt->session)
+ return -ENOTCONN;
if (ctxt->session)
sdp_close(ctxt->session);
--
1.6.4.4
next reply other threads:[~2010-07-20 23:33 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-20 23:33 Manuel Naranjo [this message]
2010-07-21 10:19 ` [PATCH][RFC] Fix SDP resolving segfault Johan Hedberg
2010-07-21 13:26 ` Luiz Augusto von Dentz
2010-07-21 15:15 ` Manuel Naranjo
2010-07-21 15:11 ` Manuel Naranjo
2010-07-23 20:37 ` Luiz Augusto von Dentz
2010-07-28 14:55 ` Luiz Augusto von Dentz
2010-07-28 16:17 ` Manuel Naranjo
2010-07-28 18:46 ` Manuel Naranjo
2010-07-29 8:53 ` Luiz Augusto von Dentz
2010-07-29 13:34 ` Manuel Naranjo
2010-08-03 13:21 ` Manuel Naranjo
2010-08-03 20:17 ` Luiz Augusto von Dentz
2010-08-03 20:24 ` Manuel Naranjo
2010-08-05 14:48 ` Manuel Naranjo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C46324D.5070800@aircable.net \
--to=manuel@aircable.net \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.