Blame SOURCES/0001-Connector-Don-t-crash-when-trying-to-unwatch-non-exi.patch

2dbfc6
From c06ce2520886d42e3489c6a4abf5735e6bb080b9 Mon Sep 17 00:00:00 2001
2dbfc6
From: Debarshi Ray <debarshir@freedesktop.org>
2dbfc6
Date: Mon, 19 Jan 2015 19:24:05 +0100
2dbfc6
Subject: [PATCH] [Connector] Don't crash when trying to unwatch non-existent
2dbfc6
 client
2dbfc6
2dbfc6
$ gdbus call \
2dbfc6
    --session \
2dbfc6
    --dest com.intel.dleyna-renderer \
2dbfc6
    --object-path /com/intel/dLeynaRenderer \
2dbfc6
    --method com.intel.dLeynaRenderer.Manager.Release
2dbfc6
2dbfc6
If a service is spawned as a result of the above command, then it will
2dbfc6
lead to a crash with this backtrace:
2dbfc6
2dbfc6
    (client_name=0x7f7c94009750 ":1.603") at src/connector-dbus.c:271
2dbfc6
    (conn=<optimized out>, sender=0x7f7c94009750 ":1.603",
2dbfc6
    object=<optimized out>, interface=<optimized out>,
2dbfc6
    method=<optimized out>, parameters=<optimized out>,
2dbfc6
    invocation=0x2360e00) at server.c:780
2dbfc6
    at gdbusconnection.c:4884
2dbfc6
    at gmain.c:3111
2dbfc6
    (context=context@entry=0x2342ea0) at gmain.c:3710
2dbfc6
    block=block@entry=1, dispatch=dispatch@entry=1,
2dbfc6
    self=<optimized out>) at gmain.c:3781
2dbfc6
    at gmain.c:3975
2dbfc6
    (server=<optimized out>, control_point=<optimized out>,
2dbfc6
    user_data=0x0) at libdleyna/core/main-loop.c:155
2dbfc6
    argv=<optimized out>) at daemon.c:93
2dbfc6
2dbfc6
This is because g_hash_table_lookup returns NULL which we try to
2dbfc6
dereference to get the client_id.
2dbfc6
2dbfc6
Instead of our hand-spun solution for storing unsigned integers in a
2dbfc6
GHashTable, let's use standard GLib mechanisms for doing that. We
2dbfc6
avoid this problem and reduce a g_new/g_free pair as a bonus.
2dbfc6
---
2dbfc6
 src/connector-dbus.c | 11 ++++-------
2dbfc6
 1 file changed, 4 insertions(+), 7 deletions(-)
2dbfc6
2dbfc6
diff --git a/src/connector-dbus.c b/src/connector-dbus.c
2dbfc6
index 0e16239..83774c0 100644
2dbfc6
--- a/src/connector-dbus.c
2dbfc6
+++ b/src/connector-dbus.c
2dbfc6
@@ -173,7 +173,7 @@ static gboolean prv_connector_initialize(const gchar *server_info,
2dbfc6
 	g_context.objects = g_hash_table_new_full(g_direct_hash, g_direct_equal,
2dbfc6
 						  g_free, prv_free_dbus_object);
2dbfc6
 	g_context.clients = g_hash_table_new_full(g_str_hash, g_str_equal,
2dbfc6
-						  g_free, g_free);
2dbfc6
+						  g_free, NULL);
2dbfc6
 
2dbfc6
 	g_context.root_node_info = g_dbus_node_info_new_for_xml(root_info,
2dbfc6
 								NULL);
2dbfc6
@@ -268,8 +268,8 @@ static void prv_connector_unwatch_client(const gchar *client_name)
2dbfc6
 
2dbfc6
 	DLEYNA_LOG_DEBUG("Enter");
2dbfc6
 
2dbfc6
-	client_id = *(guint *)g_hash_table_lookup(g_context.clients,
2dbfc6
-						  client_name);
2dbfc6
+	client_id = GPOINTER_TO_UINT(g_hash_table_lookup(g_context.clients,
2dbfc6
+							 client_name));
2dbfc6
 	(void) g_hash_table_remove(g_context.clients, client_name);
2dbfc6
 
2dbfc6
 	g_bus_unwatch_name(client_id);
2dbfc6
@@ -287,7 +287,6 @@ static void prv_lost_client(GDBusConnection *connection, const gchar *name,
2dbfc6
 static gboolean prv_connector_watch_client(const gchar *client_name)
2dbfc6
 {
2dbfc6
 	guint watch_id;
2dbfc6
-	guint *client_id;
2dbfc6
 	gboolean added = TRUE;
2dbfc6
 
2dbfc6
 	DLEYNA_LOG_DEBUG("Enter");
2dbfc6
@@ -301,10 +300,8 @@ static gboolean prv_connector_watch_client(const gchar *client_name)
2dbfc6
 				      G_BUS_NAME_WATCHER_FLAGS_NONE,
2dbfc6
 				      NULL, prv_lost_client, NULL,
2dbfc6
 				      NULL);
2dbfc6
-	client_id = g_new(guint, 1);
2dbfc6
-	*client_id = watch_id;
2dbfc6
 	g_hash_table_insert(g_context.clients, g_strdup(client_name),
2dbfc6
-			    client_id);
2dbfc6
+			    GUINT_TO_POINTER(watch_id));
2dbfc6
 
2dbfc6
 out:
2dbfc6
 	DLEYNA_LOG_DEBUG("Exit");
2dbfc6
-- 
2dbfc6
2.1.0
2dbfc6