beam: fix FD leaks in SendPipe

This fixes file descriptor leaks in the SendPipe function.

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
Solomon Hykes 2014-03-25 10:00:51 -07:00
parent 3b5c1c4203
commit 5df3aaeda2

View file

@ -120,6 +120,7 @@ func SendPipe(conn *net.UnixConn, data []byte) (endpoint *net.UnixConn, err erro
if err != nil {
return nil, err
}
local.Close()
if err := Send(conn, data, remote); err != nil {
return nil, err
}
@ -198,16 +199,15 @@ func USocketPair() (*net.UnixConn, *net.UnixConn, error) {
if err != nil {
return nil, nil, err
}
defer a.Close()
defer b.Close()
uA, err := FdConn(int(a.Fd()))
if err != nil {
a.Close()
b.Close()
return nil, nil, err
}
uB, err := FdConn(int(b.Fd()))
if err != nil {
a.Close()
b.Close()
uA.Close()
return nil, nil, err
}
return uA, uB, nil