]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-fdtab: Fix ref leak on fdtab clone
authorAndrei Tatar <andrei@unikraft.io>
Fri, 21 Mar 2025 09:44:00 +0000 (10:44 +0100)
committerUnikraft Bot <monkey@unikraft.io>
Thu, 24 Apr 2025 14:05:10 +0000 (14:05 +0000)
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 <andrei@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1617

lib/posix-fdtab/fdtab.c

index 2e607546bd97bab065939dd445c08cb98e064708..b3e91b7924dfd33d6ea08654976dde465061f867 100644 (file)
@@ -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;