summaryrefslogtreecommitdiff
path: root/src/lib/eio
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2018-08-15 13:03:13 -0400
committerStefan Schmidt <s.schmidt@samsung.com>2018-08-17 22:19:32 +0200
commit9f8a7acfcff7bd504d5c0f6ba18af4aa3725c267 (patch)
tree4d5975c94507aa3e6a5a032ce3bfae66d97fab6b /src/lib/eio
parent91dd1d9f4bb1f0e8a9de99dee01176cfb3fd9440 (diff)
eio/sentry: destroy event handlers when deleting sentry
this will crash due to invalid memory access if an event is triggered after the sentry is destroyed Differential Revision: https://phab.enlightenment.org/D6845
Diffstat (limited to 'src/lib/eio')
-rw-r--r--src/lib/eio/eio_sentry.c52
-rw-r--r--src/lib/eio/eio_sentry_private.h2
2 files changed, 35 insertions, 19 deletions
diff --git a/src/lib/eio/eio_sentry.c b/src/lib/eio/eio_sentry.c
index cf2b166d4b..84b958f694 100644
--- a/src/lib/eio/eio_sentry.c
+++ b/src/lib/eio/eio_sentry.c
@@ -88,23 +88,34 @@ _handle_event(void *data, int type, void *event)
88static void 88static void
89_initialize_handlers(Eio_Sentry_Data *pd) 89_initialize_handlers(Eio_Sentry_Data *pd)
90{ 90{
91 Ecore_Event_Handler *h;
91 EINA_SAFETY_ON_NULL_RETURN(pd); 92 EINA_SAFETY_ON_NULL_RETURN(pd);
92 93 pd->handlers = eina_array_new(11);
93 ecore_event_handler_add(EIO_MONITOR_FILE_CREATED, _handle_event, pd); 94
94 ecore_event_handler_add(EIO_MONITOR_FILE_DELETED, _handle_event, pd); 95 h = ecore_event_handler_add(EIO_MONITOR_FILE_CREATED, _handle_event, pd);
95 ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, _handle_event, pd); 96 eina_array_push(pd->handlers, h);
96 ecore_event_handler_add(EIO_MONITOR_FILE_CLOSED, _handle_event, pd); 97 h = ecore_event_handler_add(EIO_MONITOR_FILE_DELETED, _handle_event, pd);
97 98 eina_array_push(pd->handlers, h);
98 ecore_event_handler_add(EIO_MONITOR_DIRECTORY_CREATED, _handle_event, pd); 99 h = ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, _handle_event, pd);
99 ecore_event_handler_add(EIO_MONITOR_DIRECTORY_DELETED, _handle_event, pd); 100 eina_array_push(pd->handlers, h);
100 ecore_event_handler_add(EIO_MONITOR_DIRECTORY_MODIFIED, _handle_event, pd); 101 h = ecore_event_handler_add(EIO_MONITOR_FILE_CLOSED, _handle_event, pd);
101 ecore_event_handler_add(EIO_MONITOR_DIRECTORY_CLOSED, _handle_event, pd); 102 eina_array_push(pd->handlers, h);
102 103
103 ecore_event_handler_add(EIO_MONITOR_SELF_RENAME, _handle_event, pd); 104 h = ecore_event_handler_add(EIO_MONITOR_DIRECTORY_CREATED, _handle_event, pd);
104 ecore_event_handler_add(EIO_MONITOR_SELF_DELETED, _handle_event, pd); 105 eina_array_push(pd->handlers, h);
105 ecore_event_handler_add(EIO_MONITOR_ERROR, _handle_event, pd); 106 h = ecore_event_handler_add(EIO_MONITOR_DIRECTORY_DELETED, _handle_event, pd);
106 107 eina_array_push(pd->handlers, h);
107 pd->handlers_initialized = EINA_TRUE; 108 h = ecore_event_handler_add(EIO_MONITOR_DIRECTORY_MODIFIED, _handle_event, pd);
109 eina_array_push(pd->handlers, h);
110 h = ecore_event_handler_add(EIO_MONITOR_DIRECTORY_CLOSED, _handle_event, pd);
111 eina_array_push(pd->handlers, h);
112
113 h = ecore_event_handler_add(EIO_MONITOR_SELF_RENAME, _handle_event, pd);
114 eina_array_push(pd->handlers, h);
115 h = ecore_event_handler_add(EIO_MONITOR_SELF_DELETED, _handle_event, pd);
116 eina_array_push(pd->handlers, h);
117 h = ecore_event_handler_add(EIO_MONITOR_ERROR, _handle_event, pd);
118 eina_array_push(pd->handlers, h);
108} 119}
109 120
110Eina_Bool 121Eina_Bool
@@ -113,7 +124,7 @@ _eio_sentry_add(Eo *obj EINA_UNUSED, Eio_Sentry_Data *pd, const char *path)
113 EINA_SAFETY_ON_NULL_RETURN_VAL(path, EINA_FALSE); 124 EINA_SAFETY_ON_NULL_RETURN_VAL(path, EINA_FALSE);
114 EINA_SAFETY_ON_NULL_RETURN_VAL(pd, EINA_FALSE); 125 EINA_SAFETY_ON_NULL_RETURN_VAL(pd, EINA_FALSE);
115 126
116 if (!pd->handlers_initialized) 127 if (!pd->handlers)
117 _initialize_handlers(pd); 128 _initialize_handlers(pd);
118 129
119 if (eina_hash_find(pd->targets, path)) 130 if (eina_hash_find(pd->targets, path))
@@ -165,7 +176,6 @@ Efl_Object * _eio_sentry_efl_object_constructor(Eo *obj, Eio_Sentry_Data *pd)
165 176
166 pd->object = obj; 177 pd->object = obj;
167 pd->targets = eina_hash_string_small_new((Eina_Free_Cb)&eio_monitor_del); 178 pd->targets = eina_hash_string_small_new((Eina_Free_Cb)&eio_monitor_del);
168 pd->handlers_initialized = EINA_FALSE;
169 179
170 return obj; 180 return obj;
171} 181}
@@ -173,6 +183,12 @@ Efl_Object * _eio_sentry_efl_object_constructor(Eo *obj, Eio_Sentry_Data *pd)
173void _eio_sentry_efl_object_destructor(Eo *obj, Eio_Sentry_Data *pd) 183void _eio_sentry_efl_object_destructor(Eo *obj, Eio_Sentry_Data *pd)
174{ 184{
175 eina_hash_free(pd->targets); 185 eina_hash_free(pd->targets);
186 if (pd->handlers)
187 {
188 while (eina_array_count(pd->handlers))
189 ecore_event_handler_del(eina_array_pop(pd->handlers));
190 eina_array_free(pd->handlers);
191 }
176 192
177 efl_destructor(efl_super(obj, EIO_SENTRY_CLASS)); 193 efl_destructor(efl_super(obj, EIO_SENTRY_CLASS));
178} 194}
diff --git a/src/lib/eio/eio_sentry_private.h b/src/lib/eio/eio_sentry_private.h
index ade192fdf7..bb00e7074e 100644
--- a/src/lib/eio/eio_sentry_private.h
+++ b/src/lib/eio/eio_sentry_private.h
@@ -7,7 +7,7 @@ struct _Eio_Sentry_Data
7{ 7{
8 Eo *object; 8 Eo *object;
9 Eina_Hash *targets; 9 Eina_Hash *targets;
10 Eina_Bool handlers_initialized; 10 Eina_Array *handlers;
11}; 11};
12 12
13#endif 13#endif