libtailscale: remove double-close on connections

If a client program receives the fd then it is responsible for closing
the fd, and we must not close the fd, as we may end up closing the wrong
object.
This commit is contained in:
James Tucker
2023-03-07 13:45:45 -08:00
parent 926893f68c
commit acbc2e40b6

View File

@@ -65,9 +65,9 @@ var conns struct {
}
type conn struct {
s *tsnet.Server
c net.Conn
r, w *os.File // the r side is held by Go, w is given to C
s *tsnet.Server
c net.Conn
r *os.File // r is the local socket to the C client
}
func (s *server) recErr(err error) C.int {
@@ -213,9 +213,8 @@ func newConn(s *server, netConn net.Conn, connOut *C.int) C.int {
if err != nil {
return s.recErr(err)
}
w := os.NewFile(uintptr(fds[0]), "socketpair-w")
r := os.NewFile(uintptr(fds[1]), "socketpair-r")
c := &conn{s: s.s, c: netConn, r: r, w: w}
c := &conn{s: s.s, c: netConn, r: r}
fdC := C.int(fds[0])
conns.mu.Lock()
@@ -227,7 +226,6 @@ func newConn(s *server, netConn net.Conn, connOut *C.int) C.int {
connCleanup := func() {
r.Close()
w.Close()
conns.mu.Lock()
delete(conns.m, fdC)