netstack: check the value of IncRef() before returning a selected source IP

It's possible for IncRef() to fail (it's really TryIncRef()), so we have to
check.

PiperOrigin-RevId: 572068691
This commit is contained in:
Kevin Krakauer
2023-10-09 16:20:26 -07:00
committed by gVisor bot
parent b3de4851a6
commit 19399cd60b
@@ -480,10 +480,9 @@ func (a *AddressableEndpointState) acquirePrimaryAddressRLocked(remoteAddr tcpip
bestLen = stateLen
}
}
if best != nil {
best.IncRef()
if best != nil && best.IncRef() {
return best
}
return best
}
var deprecatedEndpoint *addressState