diff options
author | Lucas Manning <lucasmanning@google.com> | 2021-11-08 13:26:02 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-11-08 13:28:38 -0800 |
commit | 84b38f4c6e065d3f9314a8abbb3f5857ed4fa44e (patch) | |
tree | 53eb76fa6d0612696f93ec6919185ea5a37ff3f9 /pkg/tcpip/link/sharedmem | |
parent | 49d23beb283d0306c9ccf5300e73517153ddd3c2 (diff) |
Add reference counting to packet buffers.
PiperOrigin-RevId: 408426639
Diffstat (limited to 'pkg/tcpip/link/sharedmem')
-rw-r--r-- | pkg/tcpip/link/sharedmem/sharedmem.go | 1 | ||||
-rw-r--r-- | pkg/tcpip/link/sharedmem/sharedmem_server.go | 4 |
2 files changed, 5 insertions, 0 deletions
diff --git a/pkg/tcpip/link/sharedmem/sharedmem.go b/pkg/tcpip/link/sharedmem/sharedmem.go index b75522a51..8797d1bb9 100644 --- a/pkg/tcpip/link/sharedmem/sharedmem.go +++ b/pkg/tcpip/link/sharedmem/sharedmem.go @@ -413,6 +413,7 @@ func (e *endpoint) dispatchLoop(d stack.NetworkDispatcher) { pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{ Data: buffer.View(b).ToVectorisedView(), }) + defer pkt.DecRef() var src, dst tcpip.LinkAddress var proto tcpip.NetworkProtocolNumber diff --git a/pkg/tcpip/link/sharedmem/sharedmem_server.go b/pkg/tcpip/link/sharedmem/sharedmem_server.go index c39eca33f..00c8a6a3b 100644 --- a/pkg/tcpip/link/sharedmem/sharedmem_server.go +++ b/pkg/tcpip/link/sharedmem/sharedmem_server.go @@ -311,6 +311,7 @@ func (e *serverEndpoint) dispatchLoop(d stack.NetworkDispatcher) { if e.addr != "" { hdr, ok := pkt.LinkHeader().Consume(header.EthernetMinimumSize) if !ok { + pkt.DecRef() continue } eth := header.Ethernet(hdr) @@ -323,6 +324,7 @@ func (e *serverEndpoint) dispatchLoop(d stack.NetworkDispatcher) { // IP version information is at the first octet, so pulling up 1 byte. h, ok := pkt.Data().PullUp(1) if !ok { + pkt.DecRef() continue } switch header.IPVersion(h) { @@ -331,11 +333,13 @@ func (e *serverEndpoint) dispatchLoop(d stack.NetworkDispatcher) { case header.IPv6Version: proto = header.IPv6ProtocolNumber default: + pkt.DecRef() continue } } // Send packet up the stack. d.DeliverNetworkPacket(src, dst, proto, pkt) + pkt.DecRef() } e.mu.Lock() |