Skip to content

Commit

Permalink
Merge pull request #5051 from wzshiming/fix/missing-close
Browse files Browse the repository at this point in the history
Fix missing close
  • Loading branch information
dmcgowan committed Feb 26, 2021
2 parents 46c9746 + 05ef2fe commit 10bbd1a
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 10bbd1a

Please sign in to comment.