All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] client/player: Refcount registered endpoints
@ 2025-12-15 14:02 Arkadiusz Bokowy
  2025-12-15 15:01 ` bluez.test.bot
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Arkadiusz Bokowy @ 2025-12-15 14:02 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Arkadiusz Bokowy

In case when more than one adapter is available on the host, the
endpoint is registered on all of these adapters. When unregistering
we need to keep track of registration count, otherwise we might free
the endpoint structure prematurely (on the first unregister reply)
which will cause SIGSEGV.
---
 client/player.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/client/player.c b/client/player.c
index b6b02a000..cedb07d65 100644
--- a/client/player.c
+++ b/client/player.c
@@ -127,6 +127,7 @@ struct endpoint {
 	struct codec_preset *codec_preset;
 	bool broadcast;
 	struct iovec *bcode;
+	unsigned int refcount;
 };
 
 static DBusConnection *dbus_conn;
@@ -3323,6 +3324,7 @@ static void register_endpoint_reply(DBusMessage *message, void *user_data)
 	}
 
 	bt_shell_printf("Endpoint %s registered\n", ep->path);
+	ep->refcount++;
 
 	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
@@ -3737,9 +3739,13 @@ static void unregister_endpoint_reply(DBusMessage *message, void *user_data)
 
 	bt_shell_printf("Endpoint %s unregistered\n", ep->path);
 
-	local_endpoints = g_list_remove(local_endpoints, ep);
-	g_dbus_unregister_interface(dbus_conn, ep->path,
-					BLUEZ_MEDIA_ENDPOINT_INTERFACE);
+	ep->refcount--;
+
+	if (ep->refcount == 0) {
+		local_endpoints = g_list_remove(local_endpoints, ep);
+		g_dbus_unregister_interface(dbus_conn, ep->path,
+					    BLUEZ_MEDIA_ENDPOINT_INTERFACE);
+	}
 
 	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-12-15 19:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-15 14:02 [PATCH] client/player: Refcount registered endpoints Arkadiusz Bokowy
2025-12-15 15:01 ` bluez.test.bot
2025-12-15 15:10 ` [PATCH] " Luiz Augusto von Dentz
2025-12-15 15:33   ` Arkadiusz Bokowy
2025-12-15 15:38     ` Arkadiusz Bokowy
2025-12-15 15:46     ` Luiz Augusto von Dentz
2025-12-15 19:44 ` patchwork-bot+bluetooth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.