From 87b8f974c8cfac25a9d4f8dd5fdef63f050a965b Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 28 Jul 2025 17:05:49 -0700 Subject: [PATCH] setupIO: close conn on error While it does not make much sense practically, as runc is going to exit soon and all fds will be closed anyway, various linters (including SVACE) keep reporting this. Let's make them happy. Reported-by: Tigran Sogomonian Reported-by: Mikhail Dmitrichenko Signed-off-by: Kir Kolyshkin --- utils_linux.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/utils_linux.go b/utils_linux.go index 557aeee5b..bd45bf059 100644 --- a/utils_linux.go +++ b/utils_linux.go @@ -95,7 +95,7 @@ func newProcess(p *specs.Process) (*libcontainer.Process, error) { } // setupIO modifies the given process config according to the options. -func setupIO(process *libcontainer.Process, container *libcontainer.Container, createTTY, detach bool, sockpath string) (*tty, error) { +func setupIO(process *libcontainer.Process, container *libcontainer.Container, createTTY, detach bool, sockpath string) (_ *tty, Err error) { if createTTY { process.Stdin = nil process.Stdout = nil @@ -121,6 +121,11 @@ func setupIO(process *libcontainer.Process, container *libcontainer.Container, c if err != nil { return nil, err } + defer func() { + if Err != nil { + conn.Close() + } + }() t.postStart = append(t.postStart, conn) socket, err := conn.(*net.UnixConn).File() if err != nil {