drm: Rework device removal signal

By moving the remove signal right before where we assert that the assert signal
list is empty, we create a strict contract requiring the remove signals to remove
themselves. We ensure this is true by calling `backend_destroy()` upon removal,
making sure that we don't double free the device fd.

Signed-off-by: liupeng <liupeng01@kylinos.cn>
This commit is contained in:
liupeng 2026-05-08 20:47:19 +08:00
parent 36cd9344e1
commit 510cda868d
2 changed files with 14 additions and 7 deletions

View file

@ -65,7 +65,9 @@ static void backend_destroy(struct wlr_backend *backend) {
}
free(drm->name);
wlr_session_close_file(drm->session, drm->dev);
if (drm->dev) {
wlr_session_close_file(drm->session, drm->dev);
}
wl_event_source_remove(drm->drm_event);
free(drm);
}
@ -152,6 +154,7 @@ static void handle_dev_remove(struct wl_listener *listener, void *data) {
struct wlr_drm_backend *drm = wl_container_of(listener, drm, dev_remove);
wlr_log(WLR_INFO, "Destroying DRM backend for %s", drm->name);
drm->dev = NULL;
backend_destroy(&drm->backend);
}