From fad29b14b3e82fd222116073948cd8fc6e26be56 Mon Sep 17 00:00:00 2001 From: Olli-Pekka Salin Date: Tue, 3 Nov 2009 14:20:02 +0200 Subject: [PATCH] obexd: Fix obexd crash caused by calling agent_free with NULL pointer By adding g_dbus_remove_watch call in unregister_agent and NULL pointer checking in agent_free prevents obexd crash. --- obexd/src/manager.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/obexd/src/manager.c b/obexd/src/manager.c index 24ed3dbe4..95b87013b 100644 --- a/obexd/src/manager.c +++ b/obexd/src/manager.c @@ -227,6 +227,7 @@ struct agent { gboolean auth_pending; gchar *new_name; gchar *new_folder; + guint watch_id; }; static struct agent *agent = NULL; @@ -252,6 +253,9 @@ static guint listener_id = 0; static void agent_free(struct agent *agent) { + if(!agent) + return; + g_free(agent->new_folder); g_free(agent->new_name); g_free(agent->bus_name); @@ -387,8 +391,8 @@ static DBusMessage *register_agent(DBusConnection *conn, agent->bus_name = g_strdup(sender); agent->path = g_strdup(path); - g_dbus_add_disconnect_watch(conn, sender, - agent_disconnected, NULL, NULL); + agent->watch_id = g_dbus_add_disconnect_watch(conn, sender, + agent_disconnected, NULL, NULL); debug("Agent registered"); @@ -415,9 +419,13 @@ static DBusMessage *unregister_agent(DBusConnection *conn, if (strcmp(agent->bus_name, sender) != 0) return not_authorized(msg); + g_dbus_remove_watch(conn, agent->watch_id); + agent_free(agent); agent = NULL; + debug("Agent unregistered"); + return dbus_message_new_method_return(msg); } -- 2.47.3