From aecd402cc5cb9139d41397a39293176cd257fc11 Mon Sep 17 00:00:00 2001 From: neatnoise Date: Sun, 12 Jul 2026 16:42:48 +0200 Subject: [PATCH] fix(linux): avoid memory leak from unnecessary encoder re-probing On Linux, needs_encoder_reenumeration() unconditionally returned true, causing full encoder re-probing (h264, hevc, av1) on every client reconnect. Each probe cycle allocates ~20 MB of FFmpeg CBS buffers for HEVC/AV1 VPS validation that are not fully reclaimed, leading to unbounded memory growth. Fix by tracking the render device path and only re-probing when it actually changes (e.g. GPU hotplug or driver reload). --- src/platform/linux/misc.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/platform/linux/misc.cpp b/src/platform/linux/misc.cpp index f1b0a7edb5c..bfc9a472f7b 100644 --- a/src/platform/linux/misc.cpp +++ b/src/platform/linux/misc.cpp @@ -1247,7 +1247,15 @@ namespace platf { * @return Always `true` because Linux GPU changes are not tracked by this backend. */ bool needs_encoder_reenumeration() { - // We don't track GPU state, so we will always reenumerate. Fortunately, it is fast on Linux. + // Only re-probe if the GPU render device changed (hotplug, driver reload). + // Full re-probing on every reconnect leaks ~20 MB due to FFmpeg CBS + // allocations during HEVC/AV1 codec validation. + static std::string last_render_device; + auto current = platf::resolve_render_device(); + if (current == last_render_device) { + return false; + } + last_render_device = current; return true; }