Beam: fix file descriptor leaks
* Close all file descriptors successfully sent as attachment * Close duplicate file descriptors created by net.FileCon and net.UnixConn.File Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
95b759ad16
commit
be03962d64
1 changed files with 8 additions and 0 deletions
|
@ -111,6 +111,12 @@ func receiveUnix(conn *net.UnixConn) ([]byte, []int, error) {
|
|||
|
||||
func sendUnix(conn *net.UnixConn, data []byte, fds ...int) error {
|
||||
_, _, err := conn.WriteMsgUnix(data, syscall.UnixRights(fds...), nil)
|
||||
if err == nil {
|
||||
for _, fd := range fds {
|
||||
fmt.Printf("Closing sent fd %v\n", fd)
|
||||
syscall.Close(fd)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -154,8 +160,10 @@ func FdConn(fd int) (*net.UnixConn, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f.Close()
|
||||
uconn, ok := conn.(*net.UnixConn)
|
||||
if !ok {
|
||||
conn.Close()
|
||||
return nil, fmt.Errorf("%d: not a unix connection", fd)
|
||||
}
|
||||
return uconn, nil
|
||||
|
|
Loading…
Reference in a new issue