Skip to content

Commit

Permalink
Merge pull request containernetworking#97 from oilbeater/fix/link-leak
Browse files Browse the repository at this point in the history
delete link and ip if err when cmdAdd to avoid resource leak.
  • Loading branch information
bboreham committed Jan 24, 2018
2 parents 2eba56a + 1f02326 commit 2a0736c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions plugins/main/macvlan/macvlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,28 @@ func cmdAdd(args *skel.CmdArgs) error {
return err
}

// Delete link if err to avoid link leak in this ns
defer func() {
if err != nil {
netns.Do(func(_ ns.NetNS) error {
return ip.DelLinkByName(args.IfName)
})
}
}()

// run the IPAM plugin and get back the config to apply
r, err := ipam.ExecAdd(n.IPAM.Type, args.StdinData)
if err != nil {
return err
}

// Invoke ipam del if err to avoid ip leak
defer func() {
if err != nil {
ipam.ExecDel(n.IPAM.Type, args.StdinData)
}
}()

// Convert whatever the IPAM result was into the current Result type
result, err := current.NewResultFromResult(r)
if err != nil {
Expand Down

0 comments on commit 2a0736c

Please sign in to comment.