summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorIván Briano <sachieru@gmail.com>2012-06-27 19:01:16 +0000
committerIván Briano <sachieru@gmail.com>2012-06-27 19:01:16 +0000
commit18b94b39c143e247094f3ff9cade287ff03af181 (patch)
tree7854775a890ced8414363ccf2c0c22a220859363 /legacy
parent5a47783517f13a35a48d14b3061b43ad142e26a6 (diff)
Prevent using freed data in epoll events
SVN revision: 72960
Diffstat (limited to 'legacy')
-rw-r--r--legacy/evas/src/bin/evas_cserve2_main_loop_linux.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/legacy/evas/src/bin/evas_cserve2_main_loop_linux.c b/legacy/evas/src/bin/evas_cserve2_main_loop_linux.c
index e8cc33d851..6063925e56 100644
--- a/legacy/evas/src/bin/evas_cserve2_main_loop_linux.c
+++ b/legacy/evas/src/bin/evas_cserve2_main_loop_linux.c
@@ -26,6 +26,7 @@ struct _Watch_Data
26 Fd_Flags flags; 26 Fd_Flags flags;
27 Fd_Watch_Cb callback; 27 Fd_Watch_Cb callback;
28 const void *user_data; 28 const void *user_data;
29 Eina_Bool deleted : 1;
29}; 30};
30 31
31typedef struct _Watch_Data Watch_Data; 32typedef struct _Watch_Data Watch_Data;
@@ -47,6 +48,7 @@ static int socket_fd = -1;
47static int inotify_fd = -1; 48static int inotify_fd = -1;
48static struct sockaddr_un socket_local; 49static struct sockaddr_un socket_local;
49static Eina_Hash *watch_list; 50static Eina_Hash *watch_list;
51static Eina_List *deleted_watch_list;
50static Eina_Hash *inotify_path_hash; 52static Eina_Hash *inotify_path_hash;
51static Eina_Hash *inotify_id_hash; 53static Eina_Hash *inotify_id_hash;
52static Eina_Bool running; 54static Eina_Bool running;
@@ -354,7 +356,9 @@ _inotifyfd_finish(void)
354static void 356static void
355_watch_data_free_cb(void *data) 357_watch_data_free_cb(void *data)
356{ 358{
357 free(data); 359 Watch_Data *wd = data;
360 wd->deleted = EINA_TRUE;
361 deleted_watch_list = eina_list_append(deleted_watch_list, wd);
358} 362}
359 363
360Eina_Bool 364Eina_Bool
@@ -444,6 +448,8 @@ error_socket:
444void 448void
445cserve2_main_loop_finish(void) 449cserve2_main_loop_finish(void)
446{ 450{
451 Watch_Data *wd;
452
447 _socketfd_finish(); 453 _socketfd_finish();
448 454
449 _signalfd_finish(); 455 _signalfd_finish();
@@ -451,6 +457,8 @@ cserve2_main_loop_finish(void)
451 _inotifyfd_finish(); 457 _inotifyfd_finish();
452 458
453 eina_hash_free(watch_list); 459 eina_hash_free(watch_list);
460 EINA_LIST_FREE(deleted_watch_list, wd)
461 free(wd);
454 462
455 close(epoll_fd); 463 close(epoll_fd);
456} 464}
@@ -726,6 +734,7 @@ cserve2_main_loop_run(void)
726 { 734 {
727 struct epoll_event events[MAX_EPOLL_EVENTS]; 735 struct epoll_event events[MAX_EPOLL_EVENTS];
728 int n, nfds; 736 int n, nfds;
737 Watch_Data *data;
729 738
730 if (terminate) 739 if (terminate)
731 break; 740 break;
@@ -748,12 +757,15 @@ cserve2_main_loop_run(void)
748 757
749 for (n = 0; n < nfds; n++) 758 for (n = 0; n < nfds; n++)
750 { 759 {
751 Watch_Data *data = events[n].data.ptr; 760 data = events[n].data.ptr;
752 Fd_Flags flags = 0; 761 Fd_Flags flags = 0;
753 762
754 if (!data) 763 if (!data)
755 continue; 764 continue;
756 765
766 if (data->deleted)
767 continue;
768
757 if (!data->callback) 769 if (!data->callback)
758 continue; 770 continue;
759 771
@@ -766,6 +778,9 @@ cserve2_main_loop_run(void)
766 data->callback(data->fd, flags, (void *)data->user_data); 778 data->callback(data->fd, flags, (void *)data->user_data);
767 } 779 }
768 780
781 EINA_LIST_FREE(deleted_watch_list, data)
782 free(data);
783
769 _update_timeout(); 784 _update_timeout();
770 } 785 }
771 786