notify_socket: close fds on error

Reported in issue 5008.

Reported-by: Arina Cherednik <arinacherednik034@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2025-11-12 13:39:33 -08:00
parent 8a9b4dcda6
commit 93792e6c13

View File

@@ -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()