ClosesRenderNodeDescriptorWhenDeviceCreationFails no longer predicts the
descriptor with a probe open()/close(): open_fake_render_node() records
the descriptor it returned, and the test checks that one, so another
thread claiming the number between the calls cannot make it flaky or
check the wrong fd.
DoesNotCreateDeviceWhenRenderNodeFailsToOpen covers the early return in
gbm_device_t::init(): with open_render_node returning -1, create_device
is never called (counted by the fake accessors), and the owner stays
empty (no device, fd() == -1, nothing destroyed).
`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>