From e469d6b99d332d462648102f4149bc6e5e42e51e Mon Sep 17 00:00:00 2001 From: Ted Yu Date: Wed, 10 Jun 2020 01:06:42 -0700 Subject: [PATCH] virtcontainers: Check the correct error variable for sandbox creation This PR makes the deferred func check the correct error variable. Fixes #2759 Signed-off-by: Ted Yu --- src/runtime/virtcontainers/sandbox.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/runtime/virtcontainers/sandbox.go b/src/runtime/virtcontainers/sandbox.go index 083b9a5f1a..a01a360d39 100644 --- a/src/runtime/virtcontainers/sandbox.go +++ b/src/runtime/virtcontainers/sandbox.go @@ -505,7 +505,7 @@ func createSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Fac return s, nil } -func newSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factory) (*Sandbox, error) { +func newSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factory) (sb *Sandbox, retErr error) { span, ctx := trace(ctx, "newSandbox") defer span.Finish() @@ -547,8 +547,8 @@ func newSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor } defer func() { - if err != nil { - s.Logger().WithError(err).WithField("sandboxid", s.id).Error("Create new sandbox failed") + if retErr != nil { + s.Logger().WithError(retErr).WithField("sandboxid", s.id).Error("Create new sandbox failed") globalSandboxList.removeSandbox(s.id) s.newStore.Destroy(s.id) }