Skip to content

Commit 009a200

Browse files
liubinfidencio
authored andcommitted
virtiofsd: Fix file descriptors leak and return correct PID
This commit will fix two problems: - Virtiofsd process ID returned to the caller will always be 0, the pid var is never being assigned a value. - Socket listen fd may leak in case of failure of starting virtiofsd process. This is a port of kata-containers@be9ca0d Fixes: kata-containers#1931 Signed-off-by: bin <[email protected]> (cherry picked from commit 773deca) Signed-off-by: Fabiano Fidêncio <[email protected]>
1 parent 82bcf93 commit 009a200

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/runtime/virtcontainers/virtiofsd.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ func (v *virtiofsd) getSocketFD() (*os.File, error) {
7575
if err != nil {
7676
return nil, err
7777
}
78+
79+
// no longer needed since fd is a dup
7880
defer listener.Close()
7981

8082
listener.SetUnlinkOnClose(false)
@@ -98,6 +100,7 @@ func (v *virtiofsd) Start(ctx context.Context) (int, error) {
98100
if err != nil {
99101
return 0, err
100102
}
103+
defer socketFD.Close()
101104

102105
cmd.ExtraFiles = append(cmd.ExtraFiles, socketFD)
103106

@@ -128,7 +131,7 @@ func (v *virtiofsd) Start(ctx context.Context) (int, error) {
128131
v.wait = waitVirtiofsReady
129132
}
130133

131-
return pid, socketFD.Close()
134+
return cmd.Process.Pid, nil
132135
}
133136

134137
func (v *virtiofsd) Stop(ctx context.Context) error {

0 commit comments

Comments
 (0)