Fix couple of potential route leaks.

connect() can be invoked multiple times on UDP/RAW sockets and in such
a case we should release the cached route from the previous connect.

Fixes #5359

PiperOrigin-RevId: 353919891
This commit is contained in:
Bhasker Hariharan 2021-01-26 12:07:16 -08:00 committed by gVisor bot
parent 96bd076e8a
commit a90661654d
2 changed files with 9 additions and 1 deletions

View File

@ -413,7 +413,10 @@ func (e *endpoint) Connect(addr tcpip.FullAddress) *tcpip.Error {
e.RegisterNICID = nic
}
// Save the route we've connected via.
if e.route != nil {
// If the endpoint was previously connected then release any previous route.
e.route.Release()
}
e.route = route
e.connected = true

View File

@ -1009,6 +1009,11 @@ func (e *endpoint) Connect(addr tcpip.FullAddress) *tcpip.Error {
e.ID = id
e.boundBindToDevice = btd
if e.route != nil {
// If the endpoint was already connected then make sure we release the
// previous route.
e.route.Release()
}
e.route = r
e.dstPort = addr.Port
e.RegisterNICID = nicID