mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Fix unix/transport.queue reference leaks.
Fix two leaks for connectionless Unix sockets: * Double connect: Subsequent connects would leak a reference on the previously connected endpoint. * Close unconnected: Sockets which were not connected at the time of closure would leak a reference on their receiver. PiperOrigin-RevId: 256070451
This commit is contained in:
@@ -54,29 +54,24 @@ func (e *connectionlessEndpoint) isBound() bool {
|
||||
|
||||
// Close puts the endpoint in a closed state and frees all resources associated
|
||||
// with it.
|
||||
//
|
||||
// The socket will be a fresh state after a call to close and may be reused.
|
||||
// That is, close may be used to "unbind" or "disconnect" the socket in error
|
||||
// paths.
|
||||
func (e *connectionlessEndpoint) Close() {
|
||||
e.Lock()
|
||||
var r Receiver
|
||||
if e.Connected() {
|
||||
e.receiver.CloseRecv()
|
||||
r = e.receiver
|
||||
e.receiver = nil
|
||||
|
||||
if e.connected != nil {
|
||||
e.connected.Release()
|
||||
e.connected = nil
|
||||
}
|
||||
|
||||
if e.isBound() {
|
||||
e.path = ""
|
||||
}
|
||||
|
||||
e.receiver.CloseRecv()
|
||||
r := e.receiver
|
||||
e.receiver = nil
|
||||
e.Unlock()
|
||||
if r != nil {
|
||||
r.CloseNotify()
|
||||
r.Release()
|
||||
}
|
||||
|
||||
r.CloseNotify()
|
||||
r.Release()
|
||||
}
|
||||
|
||||
// BidirectionalConnect implements BoundEndpoint.BidirectionalConnect.
|
||||
@@ -139,6 +134,9 @@ func (e *connectionlessEndpoint) Connect(ctx context.Context, server BoundEndpoi
|
||||
}
|
||||
|
||||
e.Lock()
|
||||
if e.connected != nil {
|
||||
e.connected.Release()
|
||||
}
|
||||
e.connected = connected
|
||||
e.Unlock()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user