summaryrefslogtreecommitdiff
path: root/src/lib/ecore_wayland
diff options
context:
space:
mode:
authorTaehyub Kim <taehyub.kim@samsung.com>2016-11-18 19:53:14 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-11-18 19:53:15 +0900
commit3a98ee3796d7fe4bc70be99fc928dd3d89eddc4a (patch)
treec32bf390a7ee9fdf2aff8f7d2aeefe0afef7755d /src/lib/ecore_wayland
parent470478030bcc45e24a46ba1b71fe0d44c00187df (diff)
ecore_wayland: fix over writing file descriptor bug for reading
Summary: fix over writing file descriptor bug for reading. when we paste data to entry very fast, source->fd is over wrote by latest fd. It cause blocking of read function since the read function use invalid fd. so I make memorizing valid fd and using it in read function. @fix Reviewers: Hermet, jpeg, cedric, devilhorns, ManMower, raster Differential Revision: https://phab.enlightenment.org/D4410
Diffstat (limited to 'src/lib/ecore_wayland')
-rw-r--r--src/lib/ecore_wayland/ecore_wl_dnd.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/lib/ecore_wayland/ecore_wl_dnd.c b/src/lib/ecore_wayland/ecore_wl_dnd.c
index c286624d63..f40eaf7e68 100644
--- a/src/lib/ecore_wayland/ecore_wl_dnd.c
+++ b/src/lib/ecore_wayland/ecore_wl_dnd.c
@@ -31,6 +31,12 @@
31#include "ecore_wl_private.h" 31#include "ecore_wl_private.h"
32 32
33/* local structures */ 33/* local structures */
34struct _dnd_source
35{
36 Ecore_Wl_Dnd_Source *source;
37 int read_fd;
38};
39
34struct _dnd_task 40struct _dnd_task
35{ 41{
36 void *data; 42 void *data;
@@ -615,6 +621,7 @@ _ecore_wl_dnd_selection_data_receive(Ecore_Wl_Dnd_Source *source, const char *ty
615 struct epoll_event *ep = NULL; 621 struct epoll_event *ep = NULL;
616 struct _dnd_task *task = NULL; 622 struct _dnd_task *task = NULL;
617 struct _dnd_read_ctx *read_ctx = NULL; 623 struct _dnd_read_ctx *read_ctx = NULL;
624 struct _dnd_source *read_source = NULL;
618 int p[2]; 625 int p[2];
619 626
620 LOGFN(__FILE__, __LINE__, __FUNCTION__); 627 LOGFN(__FILE__, __LINE__, __FUNCTION__);
@@ -640,7 +647,12 @@ _ecore_wl_dnd_selection_data_receive(Ecore_Wl_Dnd_Source *source, const char *ty
640 epoll_fd = epoll_create1(0); 647 epoll_fd = epoll_create1(0);
641 if (epoll_fd < 0) goto err; 648 if (epoll_fd < 0) goto err;
642 649
643 task->data = source; 650 read_source = calloc(1, sizeof(struct _dnd_source));
651 if (!read_source) goto err;
652
653 read_source = source;
654 read_source->read_fd = p[0];
655 task->data = read_source;
644 task->cb = _ecore_wl_dnd_selection_data_read; 656 task->cb = _ecore_wl_dnd_selection_data_read;
645 ep->events = EPOLLIN; 657 ep->events = EPOLLIN;
646 ep->data.ptr = task; 658 ep->data.ptr = task;
@@ -653,7 +665,6 @@ _ecore_wl_dnd_selection_data_receive(Ecore_Wl_Dnd_Source *source, const char *ty
653 if (!ecore_idler_add(_ecore_wl_dnd_selection_cb_idle, read_ctx)) goto err; 665 if (!ecore_idler_add(_ecore_wl_dnd_selection_cb_idle, read_ctx)) goto err;
654 666
655 source->refcount++; 667 source->refcount++;
656 source->fd = p[0];
657 668
658 return; 669 return;
659 670
@@ -661,6 +672,7 @@ err:
661 if (ep) free(ep); 672 if (ep) free(ep);
662 if (task) free(task); 673 if (task) free(task);
663 if (read_ctx) free(read_ctx); 674 if (read_ctx) free(read_ctx);
675 if (read_source) free(read_source);
664 close(p[0]); 676 close(p[0]);
665 return; 677 return;
666} 678}
@@ -671,21 +683,23 @@ _ecore_wl_dnd_selection_data_read(void *data, Ecore_Fd_Handler *fd_handler EINA_
671 int len; 683 int len;
672 char buffer[PATH_MAX]; 684 char buffer[PATH_MAX];
673 Ecore_Wl_Dnd_Source *source; 685 Ecore_Wl_Dnd_Source *source;
686 struct _dnd_source *read_source;
674 Ecore_Wl_Event_Selection_Data_Ready *event; 687 Ecore_Wl_Event_Selection_Data_Ready *event;
675 Eina_Bool ret; 688 Eina_Bool ret;
676 689
677 LOGFN(__FILE__, __LINE__, __FUNCTION__); 690 LOGFN(__FILE__, __LINE__, __FUNCTION__);
678 691
679 source = data; 692 read_source = data;
693 source = read_source->source;
680 694
681 len = read(source->fd, buffer, sizeof buffer); 695 len = read(read_source->read_fd, buffer, sizeof buffer);
682 696
683 if (!(event = calloc(1, sizeof(Ecore_Wl_Event_Selection_Data_Ready)))) 697 if (!(event = calloc(1, sizeof(Ecore_Wl_Event_Selection_Data_Ready))))
684 return ECORE_CALLBACK_CANCEL; 698 return ECORE_CALLBACK_CANCEL;
685 699
686 if (len <= 0) 700 if (len <= 0)
687 { 701 {
688 close(source->fd); 702 close(read_source->read_fd);
689 _ecore_wl_dnd_del(source); 703 _ecore_wl_dnd_del(source);
690 event->done = EINA_TRUE; 704 event->done = EINA_TRUE;
691 event->data = NULL; 705 event->data = NULL;
@@ -742,6 +756,7 @@ _ecore_wl_dnd_selection_cb_idle(void *data)
742 if (task->cb(task->data, NULL) == ECORE_CALLBACK_CANCEL) 756 if (task->cb(task->data, NULL) == ECORE_CALLBACK_CANCEL)
743 { 757 {
744 free(ctx->ep); 758 free(ctx->ep);
759 free(task->data);
745 free(task); 760 free(task);
746 free(ctx); 761 free(ctx);
747 return ECORE_CALLBACK_CANCEL; 762 return ECORE_CALLBACK_CANCEL;