From f1587f236275f00dbff1f34fb4523b8ff509d1aa Mon Sep 17 00:00:00 2001 From: Andrei Tatar Date: Fri, 21 Mar 2025 10:44:00 +0100 Subject: [PATCH] lib/posix-fdtab: Fix ref leak on fdtab clone This change adds a missing ref release of the previous fdtab instance on clone, leading to a reference (and thus memory) leak with multi-fdtab. Signed-off-by: Andrei Tatar Approved-by: Michalis Pappas Reviewed-by: Michalis Pappas GitHub-Closes: #1617 --- lib/posix-fdtab/fdtab.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/posix-fdtab/fdtab.c b/lib/posix-fdtab/fdtab.c index 2e607546b..b3e91b792 100644 --- a/lib/posix-fdtab/fdtab.c +++ b/lib/posix-fdtab/fdtab.c @@ -485,9 +485,15 @@ static int fdtab_clone(const struct clone_args *cl_args, return 0; } else { /* Duplicate parent's fdtab */ + int r __maybe_unused; + newtab = fdtab_duplicate(tab); if (unlikely(!newtab)) return -ENOMEM; + /* Compat stop-gap: release previous duplicate ref */ + UK_ASSERT(uk_thread_uktls_var(child, active_fdtab) == tab); + r = uk_refcount_release(&tab->refcnt); + UK_ASSERT(!r); /* Cannot have been the last ref */ } uk_thread_uktls_var(child, active_fdtab) = newtab; return 0; -- 2.39.5