diff options
author | Ghanan Gowripalan <ghanan@google.com> | 2020-12-01 21:32:36 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-12-01 21:34:52 -0800 |
commit | 0c497394226b762dfd31b83bb33043d19073b0a4 (patch) | |
tree | 955ba3a7eac2637bee799da9352f38a06e6e1b55 /pkg/tcpip/stack | |
parent | 93d29719cc016a8f52ae5e28c4a3bff2d9da0c3f (diff) |
Correctly lock when listing neighbor entries
PiperOrigin-RevId: 345162450
Diffstat (limited to 'pkg/tcpip/stack')
-rw-r--r-- | pkg/tcpip/stack/neighbor_cache.go | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/pkg/tcpip/stack/neighbor_cache.go b/pkg/tcpip/stack/neighbor_cache.go index 0d3f626cf..317f6871d 100644 --- a/pkg/tcpip/stack/neighbor_cache.go +++ b/pkg/tcpip/stack/neighbor_cache.go @@ -182,14 +182,15 @@ func (n *neighborCache) removeWaker(addr tcpip.Address, waker *sleep.Waker) { // entries returns all entries in the neighbor cache. func (n *neighborCache) entries() []NeighborEntry { - entries := make([]NeighborEntry, 0, len(n.cache)) n.mu.RLock() + defer n.mu.RUnlock() + + entries := make([]NeighborEntry, 0, len(n.cache)) for _, entry := range n.cache { entry.mu.RLock() entries = append(entries, entry.neigh) entry.mu.RUnlock() } - n.mu.RUnlock() return entries } |