jackdanielz pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=3160b044fb8025ce36ce0be71f898a788889fe39
commit 3160b044fb8025ce36ce0be71f898a788889fe39 Author: Daniel Hirt <daniel.h...@samsung.com> Date: Tue Feb 4 15:27:02 2014 +0200 ecore_x_selection: fix selection data freeing This fixes valgrind reporting lost bytes when selecting text (e.g. in entry). Can be reproduced in any program that has entry: Simply run it with valgrind, select any text, and then exit. Fixed by properly freeing the selection data, since it is either cleared or replaced. Also, changed argument in sizeof since it didn't match the type of selections[in]. --- src/lib/ecore_x/xcb/ecore_xcb_selection.c | 11 ++++++----- src/lib/ecore_x/xlib/ecore_x_selection.c | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/lib/ecore_x/xcb/ecore_xcb_selection.c b/src/lib/ecore_x/xcb/ecore_xcb_selection.c index 85bcac7..a9a2615 100644 --- a/src/lib/ecore_x/xcb/ecore_xcb_selection.c +++ b/src/lib/ecore_x/xcb/ecore_xcb_selection.c @@ -624,6 +624,12 @@ _ecore_xcb_selection_set(Ecore_X_Window win, else return EINA_FALSE; + if (selections[in].data) + { + free(selections[in].data); + memset(&selections[in], 0, sizeof(Ecore_X_Selection_Intern)); + } + if (data) { unsigned char *buff = NULL; @@ -638,11 +644,6 @@ _ecore_xcb_selection_set(Ecore_X_Window win, memcpy(buff, data, size); _selections[in].data = buff; } - else if (_selections[in].data) - { - free(_selections[in].data); - memset(&_selections[in], 0, sizeof(Ecore_X_Selection_Data)); - } return EINA_TRUE; } diff --git a/src/lib/ecore_x/xlib/ecore_x_selection.c b/src/lib/ecore_x/xlib/ecore_x_selection.c index 6e38fcf..d146fbd 100644 --- a/src/lib/ecore_x/xlib/ecore_x_selection.c +++ b/src/lib/ecore_x/xlib/ecore_x_selection.c @@ -140,6 +140,12 @@ _ecore_x_selection_set(Window w, else return EINA_FALSE; + if (selections[in].data) + { + free(selections[in].data); + memset(&selections[in], 0, sizeof(Ecore_X_Selection_Intern)); + } + if (data) { selections[in].win = w; @@ -152,11 +158,6 @@ _ecore_x_selection_set(Window w, memcpy(buf, data, size); selections[in].data = buf; } - else if (selections[in].data) - { - free(selections[in].data); - memset(&selections[in], 0, sizeof(Ecore_X_Selection_Data)); - } return EINA_TRUE; } --