mirror of
https://github.com/LizardByte/Sunshine.git
synced 2026-12-05 03:27:36 +00:00
`dmabuf_t::init_gbm()` opens the render node and hands the descriptor to `gbm_create_device()`; the destructor destroys the GBM device but never closes the descriptor, on the assumption that GBM owns it. It does not: libgbm leaves the fd to the caller (`gbm_device_destroy()` does not close it). Every capture (re)initialisation constructs a new `dmabuf_t` -- one per streaming session start, plus one per output mode change and per encoder validation pass that reaches a real capture -- so the process keeps one open `/dev/dri/renderD*` descriptor per (re)init for its lifetime. Measured on a long-running host (Hyprland, `capture = wlr`, `encoder = nvenc`, NVIDIA 610.57.04, v2026.516.143833; unchanged on master): `/dev/dri` descriptors went 4 -> 8 across three Moonlight connect / disconnect cycles and only a restart of Sunshine returned them. Own the descriptor together with the device in a small RAII type, `wl::gbm_device_t`, whose `reset()` destroys the device and then closes the descriptor (and which closes it when device creation fails); open it with `O_CLOEXEC` so prep/do commands do not inherit it. The open/create/ destroy calls are injectable (`gbm_device_accessors_t`, same shape as `gbm_bo_accessors_t`) so the lifecycle is covered by unit tests that need no GPU: the descriptor is closed on reset, on the failure path and on destruction. Signed-off-by: Raphael Derosso Pereira <raphael@insignis.com.br>