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/tun | |
parent | 49d23beb283d0306c9ccf5300e73517153ddd3c2 (diff) |
Add reference counting to packet buffers.
PiperOrigin-RevId: 408426639
Diffstat (limited to 'pkg/tcpip/link/tun')
-rw-r--r-- | pkg/tcpip/link/tun/device.go | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/pkg/tcpip/link/tun/device.go b/pkg/tcpip/link/tun/device.go index fa2131c28..5230ac281 100644 --- a/pkg/tcpip/link/tun/device.go +++ b/pkg/tcpip/link/tun/device.go @@ -76,6 +76,7 @@ func (d *Device) Release(ctx context.Context) { // Decrease refcount if there is an endpoint associated with this file. if d.endpoint != nil { + d.endpoint.Drain() d.endpoint.RemoveNotify(d.notifyHandle) d.endpoint.DecRef(ctx) d.endpoint = nil @@ -231,6 +232,7 @@ func (d *Device) Write(data []byte) (int64, error) { ReserveHeaderBytes: len(ethHdr), Data: buffer.View(data).ToVectorisedView(), }) + defer pkt.DecRef() copy(pkt.LinkHeader().Push(len(ethHdr)), ethHdr) endpoint.InjectLinkAddr(protocol, remote, pkt) return dataLen, nil |