From: Mikel Astiz <[email protected]>
audio_adapter_get() increases the reference counter of the adapter, so
it's necessary to decrement it in case of error.
---
audio/manager.c | 21 ++++++++++++++++++---
1 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/audio/manager.c b/audio/manager.c
index 68a0a56..f15893d 100644
--- a/audio/manager.c
+++ b/audio/manager.c
@@ -964,12 +964,17 @@ static void headset_server_remove(struct btd_adapter *adapter)
static int gateway_server_probe(struct btd_adapter *adapter)
{
struct audio_adapter *adp;
+ int err;
adp = audio_adapter_get(adapter);
if (!adp)
return -EINVAL;
- return gateway_server_init(adp);
+ err = gateway_server_init(adp);
+ if (err < 0)
+ audio_adapter_unref(adp);
+
+ return err;
}
static void gateway_server_remove(struct btd_adapter *adapter)
@@ -1040,6 +1045,7 @@ static int avrcp_server_probe(struct btd_adapter *adapter)
struct audio_adapter *adp;
const gchar *path = adapter_get_path(adapter);
bdaddr_t src;
+ int err;
DBG("path %s", path);
@@ -1049,7 +1055,11 @@ static int avrcp_server_probe(struct btd_adapter *adapter)
adapter_get_address(adapter, &src);
- return avrcp_register(connection, &src, config);
+ err = avrcp_register(connection, &src, config);
+ if (err < 0)
+ audio_adapter_unref(adp);
+
+ return err;
}
static void avrcp_server_remove(struct btd_adapter *adapter)
@@ -1074,6 +1084,7 @@ static int media_server_probe(struct btd_adapter *adapter)
struct audio_adapter *adp;
const gchar *path = adapter_get_path(adapter);
bdaddr_t src;
+ int err;
DBG("path %s", path);
@@ -1083,7 +1094,11 @@ static int media_server_probe(struct btd_adapter *adapter)
adapter_get_address(adapter, &src);
- return media_register(connection, path, &src);
+ err = media_register(connection, path, &src);
+ if (err < 0)
+ audio_adapter_unref(adp);
+
+ return err;
}
static void media_server_remove(struct btd_adapter *adapter)
--
1.7.7.6
Hi Mikel,
On Tue, Mar 13, 2012, Mikel Astiz wrote:
> audio_adapter_get() increases the reference counter of the adapter, so
> it's necessary to decrement it in case of error.
> ---
> audio/manager.c | 21 ++++++++++++++++++---
> 1 files changed, 18 insertions(+), 3 deletions(-)
All patches in this set have been applied. Thanks.
Johan
From: Mikel Astiz <[email protected]>
In the unlikely case of service record allocation error, the io channel
should be properly shut down.
---
audio/manager.c | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/audio/manager.c b/audio/manager.c
index 67941ac..7d6e69a 100644
--- a/audio/manager.c
+++ b/audio/manager.c
@@ -755,21 +755,24 @@ static int gateway_server_init(struct audio_adapter *adapter)
record = hfp_hs_record(chan);
if (!record) {
error("Unable to allocate new service record");
- return -1;
+ goto failed;
}
if (add_record_to_server(&src, record) < 0) {
error("Unable to register HFP HS service record");
sdp_record_free(record);
- g_io_channel_shutdown(adapter->hfp_hs_server, TRUE, NULL);
- g_io_channel_unref(adapter->hfp_hs_server);
- adapter->hfp_hs_server = NULL;
- return -1;
+ goto failed;
}
adapter->hfp_hs_record_id = record->handle;
return 0;
+
+failed:
+ g_io_channel_shutdown(adapter->hfp_hs_server, TRUE, NULL);
+ g_io_channel_unref(adapter->hfp_hs_server);
+ adapter->hfp_hs_server = NULL;
+ return -1;
}
static int audio_probe(struct btd_device *device, GSList *uuids)
--
1.7.7.6
From: Mikel Astiz <[email protected]>
Channel must be explicitly shut down because otherwise the reference
counter never reaches zero, due to the server installed by bt_io_listen.
---
audio/manager.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/audio/manager.c b/audio/manager.c
index f15893d..67941ac 100644
--- a/audio/manager.c
+++ b/audio/manager.c
@@ -761,6 +761,7 @@ static int gateway_server_init(struct audio_adapter *adapter)
if (add_record_to_server(&src, record) < 0) {
error("Unable to register HFP HS service record");
sdp_record_free(record);
+ g_io_channel_shutdown(adapter->hfp_hs_server, TRUE, NULL);
g_io_channel_unref(adapter->hfp_hs_server);
adapter->hfp_hs_server = NULL;
return -1;
@@ -994,6 +995,7 @@ static void gateway_server_remove(struct btd_adapter *adapter)
}
if (adp->hfp_hs_server) {
+ g_io_channel_shutdown(adp->hfp_hs_server, TRUE, NULL);
g_io_channel_unref(adp->hfp_hs_server);
adp->hfp_hs_server = NULL;
}
--
1.7.7.6