allocateNetwork: fix network sandbox not cleaned up on failure

The defer function was checking for the local `err` variable, not
on the error that was returned by the function. As a result, the
sandbox would never be cleaned up for containers that used "none"
networking, and a failiure occured during setup.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit b98b8df886)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2020-05-25 14:07:22 +02:00
parent 77e06fda0c
commit ae158b371c
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -509,7 +509,7 @@ func (daemon *Daemon) updateContainerNetworkSettings(container *container.Contai
}
}
func (daemon *Daemon) allocateNetwork(container *container.Container) error {
func (daemon *Daemon) allocateNetwork(container *container.Container) (retErr error) {
start := time.Now()
controller := daemon.netController
@ -577,7 +577,7 @@ func (daemon *Daemon) allocateNetwork(container *container.Container) error {
}
updateSandboxNetworkSettings(container, sb)
defer func() {
if err != nil {
if retErr != nil {
sb.Delete()
}
}()