From 19399cd60bd45ec7cb072b5adb9997e74d348949 Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Mon, 9 Oct 2023 16:16:53 -0700 Subject: [PATCH] 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 --- pkg/tcpip/stack/addressable_endpoint_state.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/tcpip/stack/addressable_endpoint_state.go b/pkg/tcpip/stack/addressable_endpoint_state.go index e1c151ebf..40be2e6a9 100644 --- a/pkg/tcpip/stack/addressable_endpoint_state.go +++ b/pkg/tcpip/stack/addressable_endpoint_state.go @@ -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