From 6f795f33e50a9df841c2450c9e9ca27087973d1e Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Wed, 31 May 2023 10:02:03 -0700 Subject: [PATCH] netstack: remove unnecessary Inc/DecRef pair in the write path The endpoint's mutex is held during the entirety of Write, so it's impossible for something to DecRef the segment via the send list. PiperOrigin-RevId: 536745711 --- pkg/tcpip/transport/tcp/endpoint.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/tcpip/transport/tcp/endpoint.go b/pkg/tcpip/transport/tcp/endpoint.go index ffd8eb415..e94944909 100644 --- a/pkg/tcpip/transport/tcp/endpoint.go +++ b/pkg/tcpip/transport/tcp/endpoint.go @@ -1600,7 +1600,6 @@ func (e *endpoint) queueSegment(p tcpip.Payloader, opts tcpip.WriteOptions) (*se size := int(buf.Size()) s := newOutgoingSegment(e.TransportEndpointInfo.ID, e.stack.Clock(), buf) e.sndQueueInfo.SndBufUsed += size - s.IncRef() e.snd.writeList.PushBack(s) return s, size, nil @@ -1618,9 +1617,6 @@ func (e *endpoint) Write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, tcp // Return if either we didn't queue anything or if an error occurred while // attempting to queue data. nextSeg, n, err := e.queueSegment(p, opts) - if nextSeg != nil { - defer nextSeg.DecRef() - } if n == 0 || err != nil { return 0, err }