aboutsummaryrefslogtreecommitdiff
path: root/backend/multi/backend.c
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-01-30 19:45:57 +0100
committeremersion <contact@emersion.fr>2018-01-30 19:45:57 +0100
commitbabdd6ccf757f18ef15b50d9f16c55031a7c1944 (patch)
tree4e1d065ea0b710c44d362b07cc941cd290d5ac46 /backend/multi/backend.c
parent704130cc1164604c5b805adf186999269e14c5a5 (diff)
backend: fix use-after-free when destroying backends
The backend destroy signal is emitted before the output_remove signal is. When the destroy signal is emitted listeners remove their output_remove listener, so the output_remove signal is never received and listeners have an invalid output pointer. The correct way to solve this would be to remove the output_remove signal completely and use the wlr_output.events.destroy signal instead. This isn't yet possible because wl_signal_emit is unsafe and listeners cannot be removed in listeners.
Diffstat (limited to 'backend/multi/backend.c')
-rw-r--r--backend/multi/backend.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/backend/multi/backend.c b/backend/multi/backend.c
index 1e574475..78f5c63b 100644
--- a/backend/multi/backend.c
+++ b/backend/multi/backend.c
@@ -42,11 +42,16 @@ static void subbackend_state_destroy(struct subbackend_state *sub) {
static void multi_backend_destroy(struct wlr_backend *wlr_backend) {
struct wlr_multi_backend *backend = (struct wlr_multi_backend *)wlr_backend;
+
wl_list_remove(&backend->display_destroy.link);
+
struct subbackend_state *sub, *next;
wl_list_for_each_safe(sub, next, &backend->backends, link) {
wlr_backend_destroy(sub->backend);
}
+
+ // Destroy this backend only after removing all sub-backends
+ wl_signal_emit(&wlr_backend->events.destroy, backend);
free(backend);
}