From 5e484c96139d2e4c93a277ff0c0caf815acb466f Mon Sep 17 00:00:00 2001 From: Iceber Gu Date: Tue, 16 Mar 2021 10:36:53 +0800 Subject: [PATCH] runtime/v2/runc: fix the defer cleanup of the NewContainer Signed-off-by: Iceber Gu --- runtime/v2/runc/container.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/v2/runc/container.go b/runtime/v2/runc/container.go index 27d434a29..c72f31413 100644 --- a/runtime/v2/runc/container.go +++ b/runtime/v2/runc/container.go @@ -42,7 +42,7 @@ import ( ) // NewContainer returns a new runc container -func NewContainer(ctx context.Context, platform stdio.Platform, r *task.CreateTaskRequest) (*Container, error) { +func NewContainer(ctx context.Context, platform stdio.Platform, r *task.CreateTaskRequest) (_ *Container, retErr error) { ns, err := namespaces.NamespaceRequired(ctx) if err != nil { return nil, errors.Wrap(err, "create namespace") @@ -97,9 +97,9 @@ func NewContainer(ctx context.Context, platform stdio.Platform, r *task.CreateTa return nil, err } defer func() { - if err != nil { - if err2 := mount.UnmountAll(rootfs, 0); err2 != nil { - logrus.WithError(err2).Warn("failed to cleanup rootfs mount") + if retErr != nil { + if err := mount.UnmountAll(rootfs, 0); err != nil { + logrus.WithError(err).Warn("failed to cleanup rootfs mount") } } }()