Skip to content

Commit

Permalink
Fix missing close
Browse files Browse the repository at this point in the history
Signed-off-by: Shiming Zhang <wzshiming@foxmail.com>
  • Loading branch information
wzshiming committed Feb 18, 2021
1 parent ddcc431 commit 05ef2fe
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions runtime/v2/runc/v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()
}
}()
Expand Down

0 comments on commit 05ef2fe

Please sign in to comment.