Skip to content

Commit 1a0973d

Browse files
authored
Merge pull request #5206 from Iceber/fix-new-container
runtime/v2/runc: fix the defer cleanup of the NewContainer
2 parents 5978fe8 + 5e484c9 commit 1a0973d

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

runtime/v2/runc/container.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
)
4343

4444
// NewContainer returns a new runc container
45-
func NewContainer(ctx context.Context, platform stdio.Platform, r *task.CreateTaskRequest) (*Container, error) {
45+
func NewContainer(ctx context.Context, platform stdio.Platform, r *task.CreateTaskRequest) (_ *Container, retErr error) {
4646
ns, err := namespaces.NamespaceRequired(ctx)
4747
if err != nil {
4848
return nil, errors.Wrap(err, "create namespace")
@@ -97,9 +97,9 @@ func NewContainer(ctx context.Context, platform stdio.Platform, r *task.CreateTa
9797
return nil, err
9898
}
9999
defer func() {
100-
if err != nil {
101-
if err2 := mount.UnmountAll(rootfs, 0); err2 != nil {
102-
logrus.WithError(err2).Warn("failed to cleanup rootfs mount")
100+
if retErr != nil {
101+
if err := mount.UnmountAll(rootfs, 0); err != nil {
102+
logrus.WithError(err).Warn("failed to cleanup rootfs mount")
103103
}
104104
}
105105
}()

0 commit comments

Comments
 (0)