Skip to content

Commit

Permalink
prevent memory leak when using control group factors in a policy (#17532
Browse files Browse the repository at this point in the history
)

* prevent a possible memory leak when using control group factors in a policy

* CL
  • Loading branch information
hghaf099 authored Oct 14, 2022
1 parent 46534fa commit b48b383
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog/17532.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
core: prevent memory leak when using control group factors in a policy
```
6 changes: 5 additions & 1 deletion vault/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
Expand Down
11 changes: 11 additions & 0 deletions vault/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit b48b383

Please sign in to comment.