From 750dddde69301fa612e9030dc263591e5800195c Mon Sep 17 00:00:00 2001 From: Hosang Kim Date: Fri, 5 Jan 2024 13:50:00 +0900 Subject: [PATCH] evas_device: fix evas pointer data to prevent dangling. Evas_Pointer_Data is created when device is added. Multiple Evas_Object can own Evas_Pointer_Data, so I added ref count to manage pointer. I fix default ref count to 1. so even if Evas_Object is deleted, ref count does not become 0. Change-Id: I8743eab91024c68339a79a4299761fd1a06be2ce --- src/lib/evas/canvas/evas_device.c | 10 +++++++++- src/lib/evas/canvas/evas_main.c | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib/evas/canvas/evas_device.c b/src/lib/evas/canvas/evas_device.c index 38b41fc..4ee7f92 100644 --- a/src/lib/evas/canvas/evas_device.c +++ b/src/lib/evas/canvas/evas_device.c @@ -113,7 +113,15 @@ _del_cb(void *data, const Efl_Event *ev) } if (_is_pointer(devtype)) - _evas_pointer_data_remove(e, ev->object, EINA_TRUE); + { + Evas_Pointer_Data *pdata = NULL; + Evas_Pointer_Seat *pseat; + EINA_INLIST_FOREACH(e->seats, pseat) + EINA_INLIST_FOREACH(pseat->pointers, pdata) + if (pdata->pointer == ev->object) break; + + if (pdata) _evas_pointer_data_unref(pdata); + } eina_hash_del_by_key(e->locks.masks, &ev->object); eina_hash_del_by_key(e->modifiers.masks, &ev->object); efl_event_callback_call(e->evas, EFL_CANVAS_SCENE_EVENT_DEVICE_REMOVED, diff --git a/src/lib/evas/canvas/evas_main.c b/src/lib/evas/canvas/evas_main.c index 9cf7c2e..622c5c6 100644 --- a/src/lib/evas/canvas/evas_main.c +++ b/src/lib/evas/canvas/evas_main.c @@ -1506,7 +1506,7 @@ _evas_pointer_data_add(Evas_Public_Data *edata, Evas_Device *pointer) pdata->pointer = pointer; pdata->seat = pseat; pseat->pointers = eina_inlist_append(pseat->pointers, EINA_INLIST_GET(pdata)); - pdata->ref_count = 0; + pdata->ref_count = 1; return pdata; } @@ -1566,7 +1566,7 @@ _evas_pointer_data_unref(Evas_Pointer_Data *pdata) { Evas_Public_Data *edata = efl_data_scope_safe_get(efl_input_device_evas_get(pdata->pointer), EVAS_CANVAS_CLASS); if(!edata) return; - _evas_pointer_data_remove(edata, pdata->pointer, EINA_TRUE); + _evas_pointer_data_remove(edata, pdata->pointer, EINA_FALSE); } } -- 2.7.4