From 7a978e354a06597521f9f6aecdc7afbddaa40297 Mon Sep 17 00:00:00 2001 From: Ted Yu Date: Wed, 15 Apr 2020 18:33:20 -0700 Subject: [PATCH] Defer netns.Close() after error check Signed-off-by: Ted Yu --- libcontainer/container_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index 40797434..d2be68fb 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -1335,11 +1335,11 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error { // The needs to be the same as during checkpointing. // We are always using 'extRootNetNS' as the key in this. netns, err := os.Open(nsPath) - defer netns.Close() if err != nil { logrus.Errorf("If a specific network namespace is defined it must exist: %s", err) return fmt.Errorf("Requested network namespace %v does not exist", nsPath) } + defer netns.Close() inheritFd := new(criurpc.InheritFd) inheritFd.Key = proto.String("extRootNetNS") // The offset of four is necessary because 0, 1, 2 and 3 is already