Skip to content

Commit f8ec13a

Browse files
cursoragentmyungjoo
andcommitted
Release DBus name owner to avoid handle leak
- persist the owner id returned by g_bus_own_name_on_connection() - unown previously owned name before reacquiring to avoid dangling owner handles - release owned DBus name during gdbus_put_system_connection() shutdown path Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: MyungJoo Ham <myungjoo.ham@samsung.com>
1 parent 0b6bae2 commit f8ec13a

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

daemon/gdbus-util.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "log.h"
1919

2020
static GDBusConnection *g_dbus_sys_conn = NULL;
21+
static guint g_dbus_name_owner_id = 0;
2122

2223
/**
2324
* @brief Export the DBus interface at the Object path on the bus connection.
@@ -56,11 +57,14 @@ name_acquired_cb (GDBusConnection * connection,
5657
int
5758
gdbus_get_name (const char *name)
5859
{
59-
guint id;
60+
if (g_dbus_name_owner_id > 0) {
61+
g_bus_unown_name (g_dbus_name_owner_id);
62+
g_dbus_name_owner_id = 0;
63+
}
6064

61-
id = g_bus_own_name_on_connection (g_dbus_sys_conn, name,
65+
g_dbus_name_owner_id = g_bus_own_name_on_connection (g_dbus_sys_conn, name,
6266
G_BUS_NAME_OWNER_FLAGS_NONE, name_acquired_cb, NULL, NULL, NULL);
63-
if (id == 0)
67+
if (g_dbus_name_owner_id == 0)
6468
return -ENOSYS;
6569

6670
return 0;
@@ -140,6 +144,11 @@ gdbus_get_system_connection (gboolean is_session)
140144
void
141145
gdbus_put_system_connection (void)
142146
{
147+
if (g_dbus_name_owner_id > 0) {
148+
g_bus_unown_name (g_dbus_name_owner_id);
149+
g_dbus_name_owner_id = 0;
150+
}
151+
143152
g_clear_object (&g_dbus_sys_conn);
144153
}
145154

0 commit comments

Comments
 (0)