prevent memory leak when using control group factors in a policy (#17532)
* prevent a possible memory leak when using control group factors in a policy * CL
This commit is contained in:
parent
2e1dc4ed24
commit
8a624c1264
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
core: prevent memory leak when using control group factors in a policy
|
||||
```
|
|
@ -260,7 +260,11 @@ func NewACL(ctx context.Context, policies []*Policy) (*ACL, error) {
|
|||
if pc.Permissions.ControlGroup != nil {
|
||||
if len(pc.Permissions.ControlGroup.Factors) > 0 {
|
||||
if existingPerms.ControlGroup == nil {
|
||||
existingPerms.ControlGroup = pc.Permissions.ControlGroup
|
||||
cg, err := pc.Permissions.ControlGroup.Clone()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
existingPerms.ControlGroup = cg
|
||||
} else {
|
||||
existingPerms.ControlGroup.Factors = append(existingPerms.ControlGroup.Factors, pc.Permissions.ControlGroup.Factors...)
|
||||
}
|
||||
|
|
|
@ -149,6 +149,17 @@ type ControlGroup struct {
|
|||
Factors []*ControlGroupFactor
|
||||
}
|
||||
|
||||
func (c *ControlGroup) Clone() (*ControlGroup, error) {
|
||||
clonedControlGroup, err := copystructure.Copy(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cg := clonedControlGroup.(*ControlGroup)
|
||||
|
||||
return cg, nil
|
||||
}
|
||||
|
||||
type ControlGroupFactor struct {
|
||||
Name string
|
||||
Identity *IdentityFactor `hcl:"identity"`
|
||||
|
|
Loading…
Reference in New Issue