From 05ef2fe2fbb8768fef65f5a7c435a83d04907d43 Mon Sep 17 00:00:00 2001 From: Shiming Zhang Date: Thu, 18 Feb 2021 13:17:49 +0800 Subject: [PATCH] Fix missing close Signed-off-by: Shiming Zhang --- runtime/v2/runc/v1/service.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/runtime/v2/runc/v1/service.go b/runtime/v2/runc/v1/service.go index 6d0140a8d..7af6a72dc 100644 --- a/runtime/v2/runc/v1/service.go +++ b/runtime/v2/runc/v1/service.go @@ -126,7 +126,7 @@ func newCommand(ctx context.Context, id, containerdBinary, containerdAddress, co return cmd, nil } -func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (string, error) { +func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (_ string, retErr error) { cmd, err := newCommand(ctx, id, containerdBinary, containerdAddress, containerdTTRPCAddress) if err != nil { return "", err @@ -147,6 +147,12 @@ func (s *service) StartShim(ctx context.Context, id, containerdBinary, container return "", err } } + defer func() { + if retErr != nil { + socket.Close() + _ = shim.RemoveSocket(address) + } + }() f, err := socket.File() if err != nil { return "", err @@ -155,11 +161,11 @@ func (s *service) StartShim(ctx context.Context, id, containerdBinary, container cmd.ExtraFiles = append(cmd.ExtraFiles, f) if err := cmd.Start(); err != nil { + f.Close() return "", err } defer func() { - if err != nil { - _ = shim.RemoveSocket(address) + if retErr != nil { cmd.Process.Kill() } }()