From: DoHyun Pyun Date: Tue, 19 Dec 2017 00:38:37 +0000 (+0900) Subject: Fix the crash issue in the a2dp select role function X-Git-Tag: accepted/tizen/unified/20180124.061545~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F13%2F164413%2F1;p=platform%2Fupstream%2Fbluez.git Fix the crash issue in the a2dp select role function Change-Id: I328a9e72358672ec1ade61e19ebd459568132785 Signed-off-by: DoHyun Pyun --- diff --git a/profiles/audio/media.c b/profiles/audio/media.c index c714798..fdd5dcc 100755 --- a/profiles/audio/media.c +++ b/profiles/audio/media.c @@ -1081,17 +1081,51 @@ static DBusMessage *a2dp_select_role(DBusConnection *conn, DBusMessage *msg, return btd_error_invalid_args(msg); if (!g_strcmp0(a2dp_role, A2DP_SINK_ROLE)) { - btd_adapter_set_a2dp_role(adapter->btd_adapter, BLUETOOTH_A2DP_SINK_ROLE); - a2dp_remove_sep(source_endpoint->sep); + if (btd_adapter_get_a2dp_role(adapter->btd_adapter) == BLUETOOTH_A2DP_SINK_ROLE) { + DBG("Already selected A2DP sink role"); + return btd_error_already_exists(msg); + } + + if (sink_endpoint == NULL) { + DBG("sink_endpoint is NULL, so can't init the sink_endpoint"); + return btd_error_not_available(msg); + } + ret = endpoint_init_a2dp_sink(sink_endpoint, current_delay_reporting, NULL); - if (!ret) + if (!ret) { DBG("could not init a2dp sink"); + return btd_error_failed(msg, "Can't init a2dp sink"); + } + + btd_adapter_set_a2dp_role(adapter->btd_adapter, BLUETOOTH_A2DP_SINK_ROLE); + + if (source_endpoint && source_endpoint->sep) + a2dp_remove_sep(source_endpoint->sep); + + source_endpoint->sep = NULL; } else if (!g_strcmp0(a2dp_role, A2DP_SOURCE_ROLE)) { - btd_adapter_set_a2dp_role(adapter->btd_adapter, BLUETOOTH_A2DP_SOURCE_ROLE); - a2dp_remove_sep(sink_endpoint->sep); + if (btd_adapter_get_a2dp_role(adapter->btd_adapter) == BLUETOOTH_A2DP_SOURCE_ROLE) { + DBG("Already selected A2DP sink role"); + return btd_error_already_exists(msg); + } + + if (source_endpoint == NULL) { + DBG("source_endpoint is NULL, so can't init the source_endpoint"); + return btd_error_not_available(msg); + } + ret = endpoint_init_a2dp_source(source_endpoint, current_delay_reporting, NULL); - if (!ret) + if (!ret) { DBG("could not init a2dp source"); + return btd_error_failed(msg, "Can't init a2dp source"); + } + + btd_adapter_set_a2dp_role(adapter->btd_adapter, BLUETOOTH_A2DP_SOURCE_ROLE); + + if (sink_endpoint && sink_endpoint->sep) + a2dp_remove_sep(sink_endpoint->sep); + + sink_endpoint->sep = NULL; } else { DBG("invalid a2dp role"); return btd_error_invalid_args(msg);