audio/avrcp: Fix crash if no player is available
It seems some Samsung Android devices may actually report no players
at all causing the following crash:
Program terminated with signal 11, Segmentation fault.
#0 set_ct_player (player=0x0, session=<value optimized out>)
at profiles/audio/avrcp.c:3139
#1 0xb76c0aab in player_remove (data=0xb849a100)
at profiles/audio/avrcp.c:3278
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 6c8ed81..c100149 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -3200,7 +3200,8 @@
session->controller->player = player;
service = btd_device_get_service(session->dev, AVRCP_TARGET_UUID);
- control_set_player(service, media_player_get_path(player->user_data));
+ control_set_player(service, player ?
+ media_player_get_path(player->user_data) : NULL);
}
static struct avrcp_player *create_ct_player(struct avrcp *session,
@@ -3330,6 +3331,10 @@
struct avrcp_player *player = data;
GSList *l;
+ /* Don't remove reserved player */
+ if (!player->id)
+ return;
+
for (l = player->sessions; l; l = l->next) {
struct avrcp *session = l->data;
struct avrcp_data *controller = session->controller;
@@ -3393,6 +3398,10 @@
g_slist_free_full(removed, player_remove);
+ /* There should always be an active player */
+ if (!session->controller->player)
+ create_ct_player(session, 0);
+
return FALSE;
}