← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~ted/indicator-appmenu/no-crashing-srsly into lp:indicator-appmenu

 

Ted Gould has proposed merging lp:~ted/indicator-appmenu/no-crashing-srsly into lp:indicator-appmenu.

Requested reviews:
  Indicator Applet Developers (indicator-applet-developers)


The most important thing here is setting the private variable.  But, there is some other good protections and messages that should get merged in as well.
-- 
https://code.launchpad.net/~ted/indicator-appmenu/no-crashing-srsly/+merge/28091
Your team ayatana-commits is subscribed to branch lp:indicator-appmenu.
=== modified file 'src/indicator-appmenu.c'
--- src/indicator-appmenu.c	2010-06-18 18:38:53 +0000
+++ src/indicator-appmenu.c	2010-06-21 18:22:27 +0000
@@ -642,8 +642,12 @@
 	}
 
 	guint xid = window_menus_get_xid(wm);
+	g_return_if_fail(xid != 0);
+
 	g_hash_table_steal(iapp->apps, GUINT_TO_POINTER(xid));
 
+	g_debug("Removing menus for %d", xid);
+
 	return;
 }
 
@@ -653,7 +657,7 @@
 {
 	g_debug("Registering window ID %d with path %s from %s", windowid, objectpath, dbus_g_method_get_sender(method));
 
-	if (g_hash_table_lookup(iapp->apps, GUINT_TO_POINTER(windowid)) == NULL) {
+	if (g_hash_table_lookup(iapp->apps, GUINT_TO_POINTER(windowid)) == NULL || windowid == 0) {
 		WindowMenus * wm = window_menus_new(windowid, dbus_g_method_get_sender(method), objectpath);
 		g_return_val_if_fail(wm != NULL, FALSE);
 
@@ -668,7 +672,11 @@
 
 		active_window_changed(iapp->matcher, NULL, BAMF_VIEW(win), iapp);
 	} else {
-		g_warning("Already have a menu for window ID %d with path %s from %s", windowid, objectpath, dbus_g_method_get_sender(method));
+		if (windowid == 0) {
+			g_warning("Can't build windows for a NULL window ID %d with path %s from %s", windowid, objectpath, dbus_g_method_get_sender(method));
+		} else {
+			g_warning("Already have a menu for window ID %d with path %s from %s", windowid, objectpath, dbus_g_method_get_sender(method));
+		}
 	}
 
 	dbus_g_method_return(method);

=== modified file 'src/window-menus.c'
--- src/window-menus.c	2010-06-15 10:07:49 +0000
+++ src/window-menus.c	2010-06-21 18:22:27 +0000
@@ -25,6 +25,7 @@
 
 #include <libdbusmenu-gtk/menu.h>
 #include <dbus/dbus-glib.h>
+#include <glib.h>
 
 #include "window-menus.h"
 
@@ -146,6 +147,8 @@
 {
 	WindowMenusPrivate * priv = WINDOW_MENUS_GET_PRIVATE(object);
 
+	g_debug("Window Menus Object finalizing for: %d", priv->windowid);
+
 	if (priv->entries != NULL) {
 		int i;
 		for (i = 0; i < priv->entries->len; i++) {
@@ -174,12 +177,18 @@
 {
 	g_debug("Creating new windows menu: %X, %s, %s", windowid, dbus_addr, dbus_object);
 
+	g_return_val_if_fail(windowid != 0, NULL);
+	g_return_val_if_fail(dbus_addr != NULL, NULL);
+	g_return_val_if_fail(dbus_object != NULL, NULL);
+
 	DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
 	g_return_val_if_fail(session_bus != NULL, NULL);
 
 	WindowMenus * newmenu = WINDOW_MENUS(g_object_new(WINDOW_MENUS_TYPE, NULL));
 	WindowMenusPrivate * priv = WINDOW_MENUS_GET_PRIVATE(newmenu);
 
+	priv->windowid = windowid;
+
 	priv->props = dbus_g_proxy_new_for_name_owner(session_bus,
 	                                              dbus_addr,
 	                                              dbus_object,
@@ -214,6 +223,7 @@
 	WindowMenusPrivate * priv = WINDOW_MENUS_GET_PRIVATE(wm);
 
 	priv->props = NULL;
+	g_debug("Properties destroyed for window: %d", priv->windowid);
 
 	g_object_unref(G_OBJECT(wm));
 	return;


Follow ups