From 93792e6c1362954ffb2be86789d05c342fbfdda7 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 12 Nov 2025 13:39:33 -0800 Subject: [PATCH] notify_socket: close fds on error Reported in issue 5008. Reported-by: Arina Cherednik Signed-off-by: Kir Kolyshkin --- notify_socket.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/notify_socket.go b/notify_socket.go index c3eddaf85..5dd5d5007 100644 --- a/notify_socket.go +++ b/notify_socket.go @@ -175,12 +175,18 @@ func notifyHost(client *net.UnixConn, ready []byte, pid1 int) error { var errUnexpectedRead = errors.New("unexpected read from synchronization pipe") // sdNotifyBarrier performs synchronization with systemd by means of the sd_notify_barrier protocol. -func sdNotifyBarrier(client *net.UnixConn) error { +func sdNotifyBarrier(client *net.UnixConn) (retErr error) { // Create a pipe for communicating with systemd daemon. pipeR, pipeW, err := os.Pipe() if err != nil { return err } + defer func() { + if retErr != nil { + pipeW.Close() + pipeR.Close() + } + }() // Get the FD for the unix socket file to be able to use sendmsg. clientFd, err := client.File()