Skip to content

Commit 10bbd1a

Browse files
authored
Merge pull request #5051 from wzshiming/fix/missing-close
Fix missing close
2 parents 46c9746 + 05ef2fe commit 10bbd1a

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

runtime/v2/runc/v1/service.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func newCommand(ctx context.Context, id, containerdBinary, containerdAddress, co
126126
return cmd, nil
127127
}
128128

129-
func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (string, error) {
129+
func (s *service) StartShim(ctx context.Context, id, containerdBinary, containerdAddress, containerdTTRPCAddress string) (_ string, retErr error) {
130130
cmd, err := newCommand(ctx, id, containerdBinary, containerdAddress, containerdTTRPCAddress)
131131
if err != nil {
132132
return "", err
@@ -147,6 +147,12 @@ func (s *service) StartShim(ctx context.Context, id, containerdBinary, container
147147
return "", err
148148
}
149149
}
150+
defer func() {
151+
if retErr != nil {
152+
socket.Close()
153+
_ = shim.RemoveSocket(address)
154+
}
155+
}()
150156
f, err := socket.File()
151157
if err != nil {
152158
return "", err
@@ -155,11 +161,11 @@ func (s *service) StartShim(ctx context.Context, id, containerdBinary, container
155161
cmd.ExtraFiles = append(cmd.ExtraFiles, f)
156162

157163
if err := cmd.Start(); err != nil {
164+
f.Close()
158165
return "", err
159166
}
160167
defer func() {
161-
if err != nil {
162-
_ = shim.RemoveSocket(address)
168+
if retErr != nil {
163169
cmd.Process.Kill()
164170
}
165171
}()

0 commit comments

Comments
 (0)