From ae158b371ca11fe1748a16aad2e596f21da6cdfd Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 25 May 2020 14:07:22 +0200 Subject: [PATCH] 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 (cherry picked from commit b98b8df886de71da64a313bf9a17b15012a85691) Signed-off-by: Sebastiaan van Stijn --- daemon/container_operations.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/daemon/container_operations.go b/daemon/container_operations.go index 0f8e292853..a2d4212606 100644 --- a/daemon/container_operations.go +++ b/daemon/container_operations.go @@ -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() } }()