avrcp: Fix segfault when using headset controls
authorDaniel Šimko <daniel@simko.xyz>
Sat, 10 Oct 2020 22:27:28 +0000 (22:27 +0000)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:33 +0000 (19:08 +0530)
This fixes a segmentation fault caused by controls trying to notify an
unregistered player.

When an unregistered player is replaced by another valid player from the
list, the session is not referenced in the sessions list of the player
and when this player is unregistered, its reference is not removed from
the session.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
profiles/audio/avrcp.c

index 0c031a5..4e7b71d 100644 (file)
@@ -4968,8 +4968,14 @@ void avrcp_unregister_player(struct avrcp_player *player)
                if (target == NULL)
                        continue;
 
-               if (target->player == player)
-                       target->player = g_slist_nth_data(server->players, 0);
+               if (target->player != player)
+                       continue;
+
+               target->player = g_slist_nth_data(server->players, 0);
+               if (target->player)
+                       target->player->sessions = g_slist_append(
+                                               target->player->sessions,
+                                               session);
        }
 
        avrcp_player_event(player,