From 6b60dfe1556d6293b79437c6c3ffa5462a3f5b9d Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Wed, 16 Nov 2016 20:01:28 +0900 Subject: [PATCH] e_pixmap: Remove 'deleted' hash table, and renamed e_pixmap_del() to e_pixmap_win_id_del() more clearly. fix the problem that could use freed pointer as a key of hash table. Change-Id: I967ee40e5dad5d29c7e607b25866d2055ef73202 --- src/bin/e_comp_wl.c | 6 +++--- src/bin/e_pixmap.c | 34 +++++++++------------------------- src/bin/e_pixmap.h | 2 +- src/bin/e_policy_wl.c | 8 ++++---- src/bin/e_win.c | 2 +- 5 files changed, 18 insertions(+), 34 deletions(-) diff --git a/src/bin/e_comp_wl.c b/src/bin/e_comp_wl.c index 3b0dfbf75e..72e3b0de27 100644 --- a/src/bin/e_comp_wl.c +++ b/src/bin/e_comp_wl.c @@ -2977,7 +2977,7 @@ _e_comp_wl_surface_destroy(struct wl_resource *resource) ec->comp_data->surface = NULL; ec->comp_data->wl_surface = NULL; - e_pixmap_del(ec->pixmap); + e_pixmap_win_id_del(ec->pixmap); _e_comp_wl_surface_render_stop(ec); e_object_del(E_OBJECT(ec)); @@ -3024,7 +3024,7 @@ _e_comp_wl_compositor_cb_surface_create(struct wl_client *client, struct wl_reso if ((ep = e_pixmap_find(E_PIXMAP_TYPE_WL, (uintptr_t)res))) { ERR("There is e_pixmap already, Delete old e_pixmap %p", ep); - e_pixmap_del(ep); + e_pixmap_win_id_del(ep); ep = NULL; } } @@ -4378,7 +4378,7 @@ _e_comp_wl_client_usable_get(pid_t pid, E_Pixmap *ep) oldep = e_client_pixmap_change(ec, ep); if (oldep) { - e_pixmap_del(oldep); + e_pixmap_win_id_del(oldep); e_pixmap_free(oldep); } diff --git a/src/bin/e_pixmap.c b/src/bin/e_pixmap.c index 33ff1ea7ec..f3dcf03a70 100644 --- a/src/bin/e_pixmap.c +++ b/src/bin/e_pixmap.c @@ -11,7 +11,6 @@ #include static Eina_Hash *pixmaps[E_PIXMAP_TYPE_MAX] = {NULL}; -static Eina_Hash *deleted[E_PIXMAP_TYPE_MAX] = {NULL}; static Eina_Hash *res_ids = NULL; static uint32_t res_id = 0; static Eina_Hash *aliases[E_PIXMAP_TYPE_MAX] = {NULL}; @@ -269,37 +268,25 @@ e_pixmap_free(E_Pixmap *cp) _e_pixmap_hook_call(E_PIXMAP_HOOK_DEL, cp); e_pixmap_image_clear(cp, EINA_FALSE); - eina_hash_del_by_key(pixmaps[cp->type], &cp->win); eina_hash_del_by_key(res_ids, &cp->res_id); - if (e_pixmap_is_del(cp)) - eina_hash_del_by_key(deleted[cp->type], &cp->win); - else - _e_pixmap_free(cp); + if (cp->win) + eina_hash_del_by_key(pixmaps[cp->type], &cp->win); + + _e_pixmap_free(cp); return 0; } E_API void -e_pixmap_del(E_Pixmap *cp) +e_pixmap_win_id_del(E_Pixmap *cp) { if (!cp) return; if (cp->type == E_PIXMAP_TYPE_X) return; + if (!cp->win) return; - if (eina_hash_find(pixmaps[cp->type], &cp->win)) - { - eina_hash_del_by_key(pixmaps[cp->type], &cp->win); - eina_hash_add(deleted[cp->type], &cp->win, cp); - } -} - -E_API Eina_Bool -e_pixmap_is_del(E_Pixmap *cp) -{ - if (!cp) return 0; - if (cp->type == E_PIXMAP_TYPE_X) return 0; - - return !!eina_hash_find(deleted[cp->type], &cp->win); + eina_hash_del_by_key(pixmaps[cp->type], &cp->win); + cp->win = 0; } E_API E_Pixmap * @@ -339,10 +326,7 @@ e_pixmap_new(E_Pixmap_Type type, ...) } } else - { - pixmaps[type] = eina_hash_pointer_new(NULL); - deleted[type] = eina_hash_pointer_new((Eina_Free_Cb)_e_pixmap_free); - } + pixmaps[type] = eina_hash_pointer_new(NULL); cp = _e_pixmap_new(type); if (!cp) diff --git a/src/bin/e_pixmap.h b/src/bin/e_pixmap.h index 194686a332..65d88be3c5 100644 --- a/src/bin/e_pixmap.h +++ b/src/bin/e_pixmap.h @@ -38,7 +38,7 @@ struct _E_Pixmap_Hook }; E_API int e_pixmap_free(E_Pixmap *cp); -E_API void e_pixmap_del(E_Pixmap *cp); +E_API void e_pixmap_win_id_del(E_Pixmap *cp); E_API Eina_Bool e_pixmap_is_del(E_Pixmap *cp); E_API E_Pixmap *e_pixmap_ref(E_Pixmap *cp); E_API E_Pixmap *e_pixmap_new(E_Pixmap_Type type, ...); diff --git a/src/bin/e_policy_wl.c b/src/bin/e_policy_wl.c index 62bd1d75e5..04bb2f650c 100644 --- a/src/bin/e_policy_wl.c +++ b/src/bin/e_policy_wl.c @@ -557,7 +557,7 @@ _e_policy_wl_tzsh_srv_del(E_Policy_Wl_Tzsh_Srv *tzsh_srv) if (ec && ec->internal) { - e_pixmap_del(tzsh_srv->tzsh->cp); + e_pixmap_win_id_del(tzsh_srv->tzsh->cp); e_object_del(E_OBJECT(ec)); } @@ -4430,7 +4430,7 @@ _launchscreen_img_off(E_Policy_Wl_Tzlaunch_Img *tzlaunch_img) ec->ignored = EINA_TRUE; } - e_pixmap_del(tzlaunch_img->ep); + e_pixmap_win_id_del(tzlaunch_img->ep); e_object_del(E_OBJECT(ec)); } else if (!e_pixmap_resource_get(ec->pixmap)) @@ -4641,7 +4641,7 @@ _tzlaunch_img_iface_cb_owner(struct wl_client *client EINA_UNUSED, struct wl_res old_ec, new_ec, tzlaunch_img->obj); /* delete ec was created for launchscreen */ - e_pixmap_del(tzlaunch_img->ep); + e_pixmap_win_id_del(tzlaunch_img->ep); e_object_del(E_OBJECT(old_ec)); tzlaunch_img->ep = NULL; if (old_ec->visible) @@ -4711,7 +4711,7 @@ error: { ERR("Could not initialize launchscreen client"); if (tzlaunch_img->ep) - e_pixmap_del(tzlaunch_img->ep); + e_pixmap_win_id_del(tzlaunch_img->ep); if (tzlaunch_img->ec) e_object_del(E_OBJECT(tzlaunch_img->ec)); E_FREE(tzlaunch_img); diff --git a/src/bin/e_win.c b/src/bin/e_win.c index 55b5bcdc8a..f2acf47cce 100644 --- a/src/bin/e_win.c +++ b/src/bin/e_win.c @@ -113,7 +113,7 @@ _e_elm_win_trap_show(void *data, Evas_Object *o) if ((cp = e_pixmap_find(type, wl_win_id))) { ERR("There is e_pixmap already, Delete old e_pixmap %p", cp); - e_pixmap_del(cp); + e_pixmap_win_id_del(cp); cp = NULL; } /* first creation of pixmap for internal window */ -- 2.34.1