mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-28 20:45:34 +00:00
syncs: allocate map with Map.WithLock (#13755)
One primary purpose of WithLock is to mutate the underlying map. However, this can lead to a panic if it happens to be nil. Thus, always allocate a map before passing it to f. Updates tailscale/corp#11038 Signed-off-by: Joe Tsai <joetsai@digital-static.net>
This commit is contained in:
parent
c763b7a7db
commit
5b7303817e
@ -304,6 +304,9 @@ func (m *Map[K, V]) All() iter.Seq2[K, V] {
|
||||
func (m *Map[K, V]) WithLock(f func(m2 map[K]V)) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if m.m == nil {
|
||||
m.m = make(map[K]V)
|
||||
}
|
||||
f(m.m)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user