From ffc6092b8d1fe309b8c562f3c38e6d2087e4fae1 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 12 Nov 2025 13:13:48 -0800 Subject: [PATCH] [1.4] libct: startInitialization: add defer close This function calls Init what normally never returns, so the defer only works if there is an error and we can safely use it to close those fds we opened. This was done for most but not all fds. Reported in issue 5008. Reported-by: Arina Cherednik Signed-off-by: Kir Kolyshkin (cherry picked from commit 88f897160cbe25e6416e8167ed4bda9a21613634) Signed-off-by: Aleksa Sarai --- libcontainer/init_linux.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libcontainer/init_linux.go b/libcontainer/init_linux.go index 0171b4d9f..632d7c349 100644 --- a/libcontainer/init_linux.go +++ b/libcontainer/init_linux.go @@ -175,6 +175,7 @@ func startInitialization() (retErr error) { return fmt.Errorf("unable to convert _LIBCONTAINER_LOGPIPE: %w", err) } logPipe := os.NewFile(uintptr(logFd), "logpipe") + defer logPipe.Close() logrus.SetOutput(logPipe) logrus.SetFormatter(new(logrus.JSONFormatter)) @@ -190,6 +191,7 @@ func startInitialization() (retErr error) { return fmt.Errorf("unable to convert _LIBCONTAINER_FIFOFD: %w", err) } fifoFile = os.NewFile(uintptr(fifoFd), "initfifo") + defer fifoFile.Close() } var consoleSocket *os.File