cmd/cloner: deep-clone pointer elements in map-of-slice values
The cloner's codegen for map[K][]*V fields was doing a shallow append (copying pointer values) instead of cloning each element. This meant that cloned structs aliased the original's pointed-to values through the map's slice entries. Mirror the existing standalone-slice logic that checks ContainsPointers(sliceType.Elem()) and generates per-element cloning for pointer, interface, and struct types. Regenerate net/dns and tailcfg which both had affected map[...][]*dnstype.Resolver fields. Fixes #19284 Signed-off-by: Andrew Dunham <andrew@tailscale.com>
This commit is contained in:
committed by
Andrew Dunham
parent
47ecbe5845
commit
d52ae45e9b
+12
-2
@@ -33,8 +33,18 @@ func (src *Config) Clone() *Config {
|
||||
}
|
||||
if dst.Routes != nil {
|
||||
dst.Routes = map[dnsname.FQDN][]*dnstype.Resolver{}
|
||||
for k := range src.Routes {
|
||||
dst.Routes[k] = append([]*dnstype.Resolver{}, src.Routes[k]...)
|
||||
for k, sv := range src.Routes {
|
||||
if sv == nil {
|
||||
continue
|
||||
}
|
||||
dst.Routes[k] = make([]*dnstype.Resolver, len(sv))
|
||||
for i := range sv {
|
||||
if sv[i] == nil {
|
||||
dst.Routes[k][i] = nil
|
||||
} else {
|
||||
dst.Routes[k][i] = sv[i].Clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dst.SearchDomains = append(src.SearchDomains[:0:0], src.SearchDomains...)
|
||||
|
||||
Reference in New Issue
Block a user