Skip to content

Commit

Permalink
Some extra dbus safety
Browse files Browse the repository at this point in the history
As dt_dbusinit() might fail we have to make sure dereferencing is ok in dt_dbus_destroy()
and dt_dbus_connected()
  • Loading branch information
jenshannoschwalm authored and TurboGit committed Dec 1, 2024
1 parent de20f13 commit 9998ab6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/common/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,16 @@ struct dt_dbus_t *dt_dbus_init()
_on_name_lost, dbus, NULL);

dbus->dbus_connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
g_object_set(G_OBJECT(dbus->dbus_connection), "exit-on-close", FALSE, (gchar *)0);
if(dbus->dbus_connection)
g_object_set(G_OBJECT(dbus->dbus_connection), "exit-on-close", FALSE, (gchar *)0);

return dbus;
}

void dt_dbus_destroy(const dt_dbus_t *dbus)
{
if(!dbus) return;

g_bus_unown_name(dbus->owner_id);
if(dbus->introspection_data)
g_dbus_node_info_unref(dbus->introspection_data);
Expand All @@ -217,7 +220,7 @@ void dt_dbus_destroy(const dt_dbus_t *dbus)

gboolean dt_dbus_connected(const dt_dbus_t *dbus)
{
return dbus->connected;
return dbus && dbus->connected;
}

// clang-format off
Expand Down

0 comments on commit 9998ab6

Please sign in to comment.