bdilly pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=6f66c6e67696faa60e006d7f8ab41d804e799970

commit 6f66c6e67696faa60e006d7f8ab41d804e799970
Author: Bruno Dilly <bdi...@profusion.mobi>
Date:   Wed Nov 16 17:00:55 2016 -0200

    ecore_wl2: ref / unref evas devices on ecore events
    
    Summary:
    It should avoid issues when device is removed after the ecore
    event addition but before listeners are called (so pointer
    would be invalid).
    
    Reviewers: iscaro
    
    Reviewed By: iscaro
    
    Subscribers: cedric, jpeg
    
    Differential Revision: https://phab.enlightenment.org/D4407
---
 src/lib/ecore_wl2/ecore_wl2_input.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/src/lib/ecore_wl2/ecore_wl2_input.c 
b/src/lib/ecore_wl2/ecore_wl2_input.c
index a17c665..c7829f8 100644
--- a/src/lib/ecore_wl2/ecore_wl2_input.c
+++ b/src/lib/ecore_wl2/ecore_wl2_input.c
@@ -86,13 +86,21 @@ _ecore_wl2_mouse_dev_get(Ecore_Wl2_Input *input, int 
window_id)
    Ecore_Wl2_Input_Devices *devices;
 
    devices = _ecore_wl2_devices_get(input, window_id);
-   if (devices)
-     return devices->pointer_dev;
+   if (devices && devices->pointer_dev)
+     return efl_ref(devices->pointer_dev);
 
    return NULL;
 }
 
 static void
+_input_event_cb_free(void *data, void *event)
+{
+   if (data)
+     efl_unref(data);
+   free(event);
+}
+
+static void
 _ecore_wl2_input_mouse_in_send(Ecore_Wl2_Input *input, Ecore_Wl2_Window 
*window)
 {
    Ecore_Event_Mouse_IO *ev;
@@ -108,7 +116,7 @@ _ecore_wl2_input_mouse_in_send(Ecore_Wl2_Input *input, 
Ecore_Wl2_Window *window)
    ev->modifiers = input->keyboard.modifiers;
    ev->dev = _ecore_wl2_mouse_dev_get(input, window->id);
 
-   ecore_event_add(ECORE_EVENT_MOUSE_IN, ev, NULL, NULL);
+   ecore_event_add(ECORE_EVENT_MOUSE_IN, ev, _input_event_cb_free, ev->dev);
 }
 
 static void
@@ -127,7 +135,7 @@ _ecore_wl2_input_mouse_out_send(Ecore_Wl2_Input *input, 
Ecore_Wl2_Window *window
    ev->modifiers = input->keyboard.modifiers;
    ev->dev = _ecore_wl2_mouse_dev_get(input, window->id);
 
-   ecore_event_add(ECORE_EVENT_MOUSE_OUT, ev, NULL, NULL);
+   ecore_event_add(ECORE_EVENT_MOUSE_OUT, ev, _input_event_cb_free, ev->dev);
 }
 
 static void
@@ -166,7 +174,7 @@ _ecore_wl2_input_mouse_move_send(Ecore_Wl2_Input *input, 
Ecore_Wl2_Window *windo
         info->sy = input->pointer.sy;
      }
 
-   ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
+   ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _input_event_cb_free, ev->dev);
 }
 
 static void
@@ -205,7 +213,7 @@ _ecore_wl2_input_mouse_wheel_send(Ecore_Wl2_Input *input, 
unsigned int axis, int
      }
    ev->dev = _ecore_wl2_mouse_dev_get(input, ev->window);
 
-   ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, NULL, NULL);
+   ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _input_event_cb_free, ev->dev);
 }
 
 static void
@@ -296,7 +304,8 @@ _ecore_wl2_input_mouse_down_send(Ecore_Wl2_Input *input, 
Ecore_Wl2_Window *windo
         ev->dev = _ecore_wl2_mouse_dev_get(input, window->id);
      }
 
-   ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
+   ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev,
+                   _input_event_cb_free, ev->dev);
 
    if ((info) && (!info->triple_click))
      {
@@ -366,7 +375,8 @@ _ecore_wl2_input_mouse_up_send(Ecore_Wl2_Input *input, 
Ecore_Wl2_Window *window,
    ev->event_window = window->id;
    ev->dev = _ecore_wl2_mouse_dev_get(input, window->id);
 
-   ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
+   ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev,
+                   _input_event_cb_free, ev->dev);
 }
 
 static void
@@ -479,8 +489,8 @@ _ecore_wl2_keyboard_dev_get(Ecore_Wl2_Input *input, int 
window_id)
    Ecore_Wl2_Input_Devices *devices;
 
    devices = _ecore_wl2_devices_get(input, window_id);
-   if (devices)
-     return devices->keyboard_dev;
+   if (devices && devices->keyboard_dev)
+     return efl_ref(devices->keyboard_dev);
 
    return NULL;
 }
@@ -524,9 +534,9 @@ _ecore_wl2_input_key_send(Ecore_Wl2_Input *input, 
Ecore_Wl2_Window *window, xkb_
    /* DBG("Emitting Key event (%s,%s,%s,%s)\n", ev->keyname, ev->key, 
ev->compose, ev->string); */
 
    if (state)
-     ecore_event_add(ECORE_EVENT_KEY_DOWN, ev, NULL, NULL);
+     ecore_event_add(ECORE_EVENT_KEY_DOWN, ev, _input_event_cb_free, ev->dev);
    else
-     ecore_event_add(ECORE_EVENT_KEY_UP, ev, NULL, NULL);
+     ecore_event_add(ECORE_EVENT_KEY_UP, ev, _input_event_cb_free, ev->dev);
 }
 
 void

-- 


Reply via email to