[Spice-devel] [spice-gtk][PATCH] spice-widget: Don't crash when Display is NULL

Fabiano FidĂȘncio fidencio at redhat.com
Sun Nov 23 16:25:51 PST 2014


Return early or warn when SpiceDisplay is NULL instead of crash, avoiding
segfaults when running on windows using GTK3
---
 gtk/spice-widget.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index ae11073..67429f0 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -701,9 +701,12 @@ SpiceGrabSequence *spice_display_get_grab_keys(SpiceDisplay *display)
 static void try_keyboard_grab(SpiceDisplay *display)
 {
     GtkWidget *widget = GTK_WIDGET(display);
+    GdkWindow *window = gtk_widget_get_window(widget);
     SpiceDisplayPrivate *d = display->priv;
     GdkGrabStatus status;
 
+    g_return_if_fail(window != NULL);
+
     if (g_getenv("SPICE_NOGRAB"))
         return;
     if (d->disable_inputs)
@@ -731,8 +734,8 @@ static void try_keyboard_grab(SpiceDisplay *display)
                                             GetModuleHandle(NULL), 0);
     g_warn_if_fail(d->keyboard_hook != NULL);
 #endif
-    status = gdk_keyboard_grab(gtk_widget_get_window(widget), FALSE,
-                               GDK_CURRENT_TIME);
+
+    status = gdk_keyboard_grab(window, FALSE, GDK_CURRENT_TIME);
     if (status != GDK_GRAB_SUCCESS) {
         g_warning("keyboard grab failed %d", status);
         d->keyboard_grab_active = false;
@@ -1294,7 +1297,14 @@ static gboolean check_for_grab_key(SpiceDisplay *display, int type, int keyval)
 static void update_display(SpiceDisplay *display)
 {
 #ifdef G_OS_WIN32
-    win32_window = display ? GDK_WINDOW_HWND(gtk_widget_get_window(GTK_WIDGET(display))) : NULL;
+    GdkWindow *window = NULL;
+
+    if (display != NULL) {
+        window = gtk_widget_get_window(GTK_WIDGET(display));
+        g_warn_if_fail (window != NULL);
+    }
+
+    win32_window = window ? GDK_WINDOW_HWND(window) : NULL;
 #endif
 }
 
-- 
2.1.0



More information about the Spice-devel mailing list