From eb84475503da9f40d6a79eb2bff9c0a50805baee Mon Sep 17 00:00:00 2001 From: Chris Michael Date: Mon, 18 Nov 2013 07:56:13 +0000 Subject: [PATCH] Check for valid drag type before trying to strdup. When deleting the drag, free any dupped strings. Hopefully this fixes Phab Ticket T471. Don't know for sure as I cannot reproduce the crash here :/ Signed-off-by: Chris Michael --- src/lib/ecore_wayland/ecore_wl_dnd.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lib/ecore_wayland/ecore_wl_dnd.c b/src/lib/ecore_wayland/ecore_wl_dnd.c index b1bf0664f3..1104f5bd0a 100644 --- a/src/lib/ecore_wayland/ecore_wl_dnd.c +++ b/src/lib/ecore_wayland/ecore_wl_dnd.c @@ -141,7 +141,7 @@ ecore_wl_dnd_selection_set(Ecore_Wl_Input *input, const char **types_offered) for (type = types_offered; *type; type++) { t = wl_array_add(&input->data_types, sizeof(*t)); - *t = strdup(*type); + if (t) *t = strdup(*type); wl_data_source_offer(input->data_source, *t); } @@ -374,9 +374,13 @@ ecore_wl_dnd_drag_types_set(Ecore_Wl_Input *input, const char **types_offered) /* add these types to the data source */ for (type = types_offered; *type; type++) { + if (!*type) continue; t = wl_array_add(&input->data_types, sizeof(*t)); - *t = strdup(*type); - wl_data_source_offer(input->data_source, *t); + if (t) + { + *t = strdup(*type); + wl_data_source_offer(input->data_source, *t); + } } } @@ -563,6 +567,8 @@ _ecore_wl_dnd_selection(void *data, struct wl_data_device *data_device EINA_UNUS void _ecore_wl_dnd_del(Ecore_Wl_Dnd_Source *source) { + char **t; + LOGFN(__FILE__, __LINE__, __FUNCTION__); if (!source) return; @@ -570,6 +576,8 @@ _ecore_wl_dnd_del(Ecore_Wl_Dnd_Source *source) if (source->refcount == 0) { wl_data_offer_destroy(source->data_offer); + for (t = source->types.data; *t; t++) + free(*t); wl_array_release(&source->types); free(source); } @@ -779,7 +787,8 @@ _ecore_wl_dnd_offer_cb_offer(void *data, struct wl_data_offer *data_offer EINA_U LOGFN(__FILE__, __LINE__, __FUNCTION__); if (!(source = data)) return; + if (!type) return; t = wl_array_add(&source->types, sizeof(*t)); - *t = strdup(type); + if (t) *t = strdup(type); }