From 2ca7f61e481530f975f528fe4577024bdb022b60 Mon Sep 17 00:00:00 2001
From: Rob Bradford <rob@linux.intel.com>
Date: Fri, 3 Aug 2012 14:05:33 +0100
Subject: [PATCH] Ecore(wayland): Check for NULL (shell) surfaces on events

If the surface is destroyed by the client any events "in flight" sent by the
server will still be delivered to the client. However with the parameter for
the now-destroyed object set to NULL. Therefore we must check for this before
dereferencing.
---
 ChangeLog                               | 7 +++++++
 src/lib/ecore_wayland/ecore_wl_input.c  | 6 ++++++
 src/lib/ecore_wayland/ecore_wl_window.c | 4 ++++
 3 files changed, 17 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index dad80f6..d1a54eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -841,3 +841,10 @@
 	Wayland backend. Removing the need to have our own function to do this
 	and increasing the range of supported keysms. Fixes #1105.
 
+2012-08-03  Rob Bradford
+
+	* In the Wayland backend handle the case that events can be received
+	for surfaces that have been since destroyed - the client side
+	marshaller changes the pointer to NULL to when the object is destroyed
+	on the client side. Fixes #1258.
+
diff --git a/src/lib/ecore_wayland/ecore_wl_input.c b/src/lib/ecore_wayland/ecore_wl_input.c
index 61b4bf9..a5f5251 100644
--- a/src/lib/ecore_wayland/ecore_wl_input.c
+++ b/src/lib/ecore_wayland/ecore_wl_input.c
@@ -631,6 +631,7 @@ _ecore_wl_input_cb_pointer_leave(void *data, struct wl_pointer *pointer __UNUSED
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
 
+   if (!surface) return;
    if (!(input = data)) return;
 
    input->display->serial = serial;
@@ -660,6 +661,7 @@ _ecore_wl_input_cb_keyboard_enter(void *data, struct wl_keyboard *keyboard __UNU
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
 
+   if (!surface) return;
    if (!(input = data)) return;
 
    if (!input->timestamp)
@@ -688,6 +690,7 @@ _ecore_wl_input_cb_keyboard_leave(void *data, struct wl_keyboard *keyboard __UNU
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
 
+   if (!surface) return;
    if (!(input = data)) return;
 
    if (!input->timestamp)
@@ -716,6 +719,7 @@ _ecore_wl_input_cb_touch_down(void *data, struct wl_touch *touch __UNUSED__, uns
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
 
+   if (!surface) return;
    if (!(input = data)) return;
 
    /* FIXME: NB: Not sure yet if input->timestamp should be set here. 
@@ -788,6 +792,8 @@ _ecore_wl_input_cb_data_enter(void *data, struct wl_data_device *data_device, un
 {
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
 
+   if (!surface) return;
+
    _ecore_wl_dnd_enter(data, data_device, timestamp, surface, x, y, offer);
 }
 
diff --git a/src/lib/ecore_wayland/ecore_wl_window.c b/src/lib/ecore_wayland/ecore_wl_window.c
index 5cdf010..3ebe4b2 100644
--- a/src/lib/ecore_wayland/ecore_wl_window.c
+++ b/src/lib/ecore_wayland/ecore_wl_window.c
@@ -583,6 +583,7 @@ ecore_wl_window_parent_set(Ecore_Wl_Window *win, Ecore_Wl_Window *parent)
 static void 
 _ecore_wl_window_cb_ping(void *data __UNUSED__, struct wl_shell_surface *shell_surface, unsigned int serial)
 {
+   if (!shell_surface) return;
    wl_shell_surface_pong(shell_surface, serial);
 }
 
@@ -616,6 +617,7 @@ _ecore_wl_window_cb_popup_done(void *data, struct wl_shell_surface *shell_surfac
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
 
+   if (!shell_surface) return;
    if (!(win = data)) return;
    ecore_wl_input_ungrab(win->pointer_device);
 }
@@ -627,6 +629,7 @@ _ecore_wl_window_cb_surface_enter(void *data, struct wl_surface *surface, struct
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
 
+   if (!surface) return;
    if (!(win = data)) return;
 }
 
@@ -637,6 +640,7 @@ _ecore_wl_window_cb_surface_leave(void *data, struct wl_surface *surface, struct
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
 
+   if (!surface) return;
    if (!(win = data)) return;
 }
 
-- 
1.7.11.2

