Skip to content

Commit

Permalink
Fix PacketBuffer memory leak.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 410339192
  • Loading branch information
manninglucas authored and gvisor-bot committed Nov 16, 2021
1 parent 115474b commit 5117717
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/tcpip/link/sharedmem/sharedmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,13 @@ 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
if e.addr != "" {
hdr, ok := pkt.LinkHeader().Consume(header.EthernetMinimumSize)
if !ok {
pkt.DecRef()
continue
}
eth := header.Ethernet(hdr)
Expand All @@ -432,6 +432,7 @@ func (e *endpoint) 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) {
Expand All @@ -440,12 +441,14 @@ func (e *endpoint) 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()
Expand Down

0 comments on commit 5117717

Please # to comment.