Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 896f24f

Browse files
chripelldanderson
authored andcommitted
Avoid leaking a file descriptor.
1 parent e2a5cd3 commit 896f24f

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

nat_unix.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func setTOS(conn net.Conn, tos int) error {
2121
if err != nil {
2222
return fmt.Errorf("Failed to set TOS, connection retrieve the fd: %v", err)
2323
}
24+
defer f.Close()
2425
if err := syscall.SetsockoptInt(int(f.Fd()), syscall.SOL_SOCKET, syscall.IP_TOS, tos); err != nil {
2526
return fmt.Errorf("Failed to set TOS to %d: %v", tos, err)
2627
}

nat_windows.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func setTOS(conn net.Conn, tos int) error {
2121
if err != nil {
2222
return fmt.Errorf("Failed to set TOS, connection retrieve the fd: %v", err)
2323
}
24+
defer f.Close()
2425
if err := syscall.SetsockoptInt(syscall.Handle(f.Fd()), syscall.SOL_SOCKET, syscall.IP_TOS, tos); err != nil {
2526
return fmt.Errorf("Failed to set TOS to %d: %v", tos, err)
2627
}

0 commit comments

Comments
 (0)