Fix a segfault when the selected item is not a valid disco target
authorMikael Berthe <mikael@lilotux.net>
Wed, 10 Nov 2010 11:47:31 +0100
changeset 34 1a62a570e66b
parent 33 104ecab6a1d5
child 39 ab9dad1e6d66
Fix a segfault when the selected item is not a valid disco target (E.g. status buffer...)
disco.c
--- a/disco.c	Wed Nov 10 11:25:08 2010 +0100
+++ b/disco.c	Wed Nov 10 11:47:31 2010 +0100
@@ -585,12 +585,31 @@
 			if (args[2])
 				dnode = to_utf8 (args[2]);
 		}
-			// XXX send to all resources/current resource?
+
+        if (!to) {
+		    // Use currently selected item, if possible
+			if (current_buddy) {
+			    gpointer bud = BUDDATA(current_buddy);
+				if (bud) {
+					guint type = buddy_gettype (bud);
+					if (type != ROSTER_TYPE_GROUP && type != ROSTER_TYPE_SPECIAL)
+						to = g_strdup (buddy_getjid (bud)); // XXX memleak!
+				  }
+			}
+        }
+
+		if (!to) {
+		  scr_log_print (LPRINT_NORMAL, "Invalid disco target.");
+		  free_arg_lst (args);
+		  return;
+		}
+
+		// XXX send to all resources/current resource?
 
 		{
 			disco_handler_t *cb = g_new (disco_handler_t, 1);
 
-			cb -> jid  = to ? to : g_strdup (CURRENT_JID);
+			cb -> jid  = to;
 			cb -> node = dnode;
 
 			if (info)