summaryrefslogtreecommitdiff
path: root/src/lib/eio
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2019-08-23 13:22:04 -0400
committerMike Blumenkrantz <zmike@samsung.com>2019-08-23 13:38:33 -0400
commit42704eccc782d460d997630e9ab774833704c741 (patch)
tree2acea29f57769b812ff8c6af7a1f329f3f19bbaa /src/lib/eio
parent0b8605c35d89e54428b96ff04ff759208b896d7c (diff)
eio/poll: avoid ever dereferencing the backend's parent in a thread
Summary: when a monitor is destroyed, it unconditionally and immediately deletes the monitor struct. this means that as soon as the monitor is dead, the backend must never access the parent pointer again if its lifetime exceeds the lifetime of the monitor (such as in threads) the only member of the monitor data used by the fallback monitor is the monitor path, so we can just copy it to the fallback data to avoid ever needing to dereference this pointer fixes reliability issues with efl sentry unit tests @fix Depends on D9708 Reviewers: cedric Reviewed By: cedric Subscribers: #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9709
Diffstat (limited to 'src/lib/eio')
-rw-r--r--src/lib/eio/eio_monitor_poll.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/lib/eio/eio_monitor_poll.c b/src/lib/eio/eio_monitor_poll.c
index 55cdff6..2a35b6f 100644
--- a/src/lib/eio/eio_monitor_poll.c
+++ b/src/lib/eio/eio_monitor_poll.c
@@ -39,6 +39,7 @@ struct _Eio_Monitor_Stat
39struct _Eio_Monitor_Backend 39struct _Eio_Monitor_Backend
40{ 40{
41 Eio_Monitor *parent; 41 Eio_Monitor *parent;
42 Eina_Stringshare *path;
42 43
43 Eina_Stat self; 44 Eina_Stat self;
44 Eina_Hash *children; 45 Eina_Hash *children;
@@ -74,17 +75,14 @@ _eio_monitor_fallback_heavy_cb(void *data, Ecore_Thread *thread)
74 else 75 else
75 est = alloca(sizeof (Eina_Stat)); 76 est = alloca(sizeof (Eina_Stat));
76 77
77 if (!backend->parent) 78 if (_eio_stat(backend->path, &st))
78 return;
79
80 if (_eio_stat(backend->parent->path, &st))
81 { 79 {
82 if (backend->initialised && !backend->destroyed) 80 if (backend->initialised && !backend->destroyed)
83 { 81 {
84 ecore_thread_main_loop_begin(); 82 ecore_thread_main_loop_begin();
85 deleted = backend->delete_me; 83 deleted = backend->delete_me;
86 if (!deleted) 84 if (!deleted)
87 _eio_monitor_send(backend->parent, backend->parent->path, EIO_MONITOR_SELF_DELETED); 85 _eio_monitor_send(backend->parent, backend->path, EIO_MONITOR_SELF_DELETED);
88 ecore_thread_main_loop_end(); 86 ecore_thread_main_loop_end();
89 backend->destroyed = EINA_TRUE; 87 backend->destroyed = EINA_TRUE;
90 } 88 }
@@ -137,12 +135,12 @@ _eio_monitor_fallback_heavy_cb(void *data, Ecore_Thread *thread)
137 ecore_thread_main_loop_begin(); 135 ecore_thread_main_loop_begin();
138 deleted = backend->delete_me; 136 deleted = backend->delete_me;
139 if (!deleted) 137 if (!deleted)
140 _eio_monitor_send(backend->parent, backend->parent->path, event); 138 _eio_monitor_send(backend->parent, backend->path, event);
141 ecore_thread_main_loop_end(); 139 ecore_thread_main_loop_end();
142 if (deleted) return; 140 if (deleted) return;
143 } 141 }
144 142
145 it = eina_file_direct_ls(backend->parent->path); 143 it = eina_file_direct_ls(backend->path);
146 EINA_ITERATOR_FOREACH(it, info) 144 EINA_ITERATOR_FOREACH(it, info)
147 { 145 {
148 Eio_Monitor_Stat *cmp; 146 Eio_Monitor_Stat *cmp;
@@ -344,6 +342,7 @@ eio_monitor_fallback_add(Eio_Monitor *monitor)
344 342
345 backend->children = eina_hash_string_superfast_new(free); 343 backend->children = eina_hash_string_superfast_new(free);
346 backend->parent = monitor; 344 backend->parent = monitor;
345 backend->path = eina_stringshare_ref(monitor->path);
347 monitor->backend = backend; 346 monitor->backend = backend;
348 monitor->fallback = EINA_TRUE; 347 monitor->fallback = EINA_TRUE;
349 348
@@ -370,6 +369,7 @@ eio_monitor_fallback_del(Eio_Monitor *monitor)
370 if (backend->timer) ecore_timer_del(backend->timer); 369 if (backend->timer) ecore_timer_del(backend->timer);
371 eina_hash_set(timer_hash, &backend, NULL); 370 eina_hash_set(timer_hash, &backend, NULL);
372 backend->timer = NULL; 371 backend->timer = NULL;
372 backend->parent = NULL;
373 373
374 if (backend->work) 374 if (backend->work)
375 { 375 {
@@ -377,7 +377,7 @@ eio_monitor_fallback_del(Eio_Monitor *monitor)
377 return; 377 return;
378 } 378 }
379 379
380 backend->parent = NULL; 380 eina_stringshare_del(backend->path);
381 eina_hash_free(backend->children); 381 eina_hash_free(backend->children);
382 free(backend); 382 free(backend);
383} 383}