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 | 22 +++++++++++++++++++---
1 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/audio/manager.c b/audio/manager.c
index b984c33..0e09f2f 100644
--- a/audio/manager.c
+++ b/audio/manager.c
@@ -877,6 +877,7 @@ static void audio_adapter_unref(struct audio_adapter *adp)
return;
adapters = g_slist_remove(adapters, adp);
+
btd_adapter_unref(adp->btd_adapter);
g_free(adp);
}
@@ -1014,12 +1015,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)
@@ -1090,6 +1096,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);
@@ -1099,7 +1106,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)
@@ -1124,6 +1135,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);
@@ -1133,7 +1145,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
SGkgSm9oYW4sDQoNCj4g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lj
aCAoZm9ydHVuYXRlbHkpIGxlZCB0byBjb21waWxhdGlvbiBlcnJvcnMuIFNvcnJ5IGZvciB0aGUg
bWVzcy4NCg0KSSdsbCBzZW5kIGFuIHVwZGF0ZWQgdmVyc2lvbiBzb29uLg0KDQpDaGVlcnMsDQpN
aWtlbA0KDQo=
Hi Mikel,
On Tue, Mar 13, 2012, Mikel Astiz wrote:
> 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 | 22 +++++++++++++++++++---
> 1 files changed, 19 insertions(+), 3 deletions(-)
Please test at least that your patches compile before submitting them:
CC audio/bluetoothd-manager.o
audio/manager.c: In function ‘avrcp_server_probe’:
audio/manager.c:1058:2: error: ‘err’ undeclared (first use in this function)
audio/manager.c:1058:2: note: each undeclared identifier is reported only once for each function it appears in
audio/manager.c: In function ‘avrcp_server_remove’:
audio/manager.c:1070:6: error: unused variable ‘err’ [-Werror=unused-variable]
audio/manager.c: In function ‘avrcp_server_probe’:
audio/manager.c:1063:1: error: control reaches end of non-void function [-Werror=return-type]
Also:
> --- a/audio/manager.c
> +++ b/audio/manager.c
> @@ -877,6 +877,7 @@ static void audio_adapter_unref(struct audio_adapter *adp)
> return;
>
> adapters = g_slist_remove(adapters, adp);
> +
> btd_adapter_unref(adp->btd_adapter);
> g_free(adp);
> }
This added line seems completely unrelated to the patch.
Johan
From: Mikel Astiz <[email protected]>
In the unlikely case of service record allocation error, the io channel
should be dereferenced.
---
audio/manager.c | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/audio/manager.c b/audio/manager.c
index 0e09f2f..ddefd41 100644
--- a/audio/manager.c
+++ b/audio/manager.c
@@ -763,20 +763,23 @@ 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_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_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