Thanks to visit codestin.com
Credit goes to github.com

Skip to content

File may be left unclosed in runtimeVM#CreateContainer #3899

@tedyu

Description

@tedyu

Description

f, err := os.OpenFile(c.LogPath(), os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0600)

If the r.task.Create() call fails on line 135, the file would be unclosed.

Steps to reproduce the issue:
1.
2.
3.

Describe the results you received:

Describe the results you expected:
Potential fix:

diff --git a/internal/oci/runtime_vm.go b/internal/oci/runtime_vm.go
index b4c500b40..981e7e223 100644
--- a/internal/oci/runtime_vm.go
+++ b/internal/oci/runtime_vm.go
@@ -141,6 +141,7 @@ func (r *runtimeVM) CreateContainer(c *Container, cgroupParent string) (err erro

        select {
        case err = <-createdCh:
+               f.Close()
                if err != nil {
                        return errors.Errorf("CreateContainer failed: %v", err)
                }

Additional information you deem important (e.g. issue happens only occasionally):

Output of crio --version:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions