Skip to content

Commit 5c67cc3

Browse files
committed
notify_socket: close fds on error
Reported in issue 5008. Reported-by: Arina Cherednik <[email protected]> Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent b5eae07 commit 5c67cc3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

notify_socket.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,18 @@ func notifyHost(client *net.UnixConn, ready []byte, pid1 int) error {
175175
var errUnexpectedRead = errors.New("unexpected read from synchronization pipe")
176176

177177
// sdNotifyBarrier performs synchronization with systemd by means of the sd_notify_barrier protocol.
178-
func sdNotifyBarrier(client *net.UnixConn) error {
178+
func sdNotifyBarrier(client *net.UnixConn) (retErr error) {
179179
// Create a pipe for communicating with systemd daemon.
180180
pipeR, pipeW, err := os.Pipe()
181181
if err != nil {
182182
return err
183183
}
184+
defer func() {
185+
if retErr != nil {
186+
pipeW.Close()
187+
pipeR.Close()
188+
}
189+
}()
184190

185191
// Get the FD for the unix socket file to be able to use sendmsg.
186192
clientFd, err := client.File()

0 commit comments

Comments
 (0)