Close leaked file handles in container config, CRIU stats, and playbook read#28724
Merged
Merged
Conversation
…ok read Add missing defer Close() calls in four locations: - libpod/container.go: specFromState() opens the container config file but never closes it after reading, leaking one fd per call. - libpod/container_internal_common.go: checkpoint() and restore() each open the bundle directory for CRIU statistics but never close it, leaking one fd per checkpoint/restore operation. - pkg/machine/shim/host.go: Init() opens the playbook file but never closes it after ReadAll, leaking one fd per machine init. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Honny1
approved these changes
May 18, 2026
Member
Honny1
left a comment
There was a problem hiding this comment.
Thanks, LGTM
Adding label No New Tests and retriggering CI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds missing
defer Close()calls in four locations where file handles are opened but never closed:libpod/container.go(specFromState):os.Open(c.state.ConfigPath)reads the container config but the file handlefis never closed, leaking one fd per call. Introduced in apparmor: apply default profile at container initialization #2114 (2019-01-09).libpod/container_internal_common.go(checkpoint):os.Open(c.bundlePath())opens the bundle directory for CRIU dump statistics but thestatsDirectoryhandle is never closed, leaking one fd per checkpoint operation. Introduced in Add support for FreeBSD containers #15632 (2022-08-27).libpod/container_internal_common.go(restore): Same pattern as checkpoint;statsDirectoryopened for CRIU restore statistics is never closed. Introduced in Add support for FreeBSD containers #15632 (2022-08-27).pkg/machine/shim/host.go(Init):os.Open(opts.PlaybookPath)reads the playbook file but the handlefis never closed afterio.ReadAll. Introduced in Addmachine init --playbook#25043 (2025-01-17).How was this tested?
These are mechanical
defer Close()additions following the same pattern as #28723 (which was accepted for the same class of fix inpkg/trust/registries.go). The functions involved require complex runtime state (Container with CRIU, machine providers) that makes isolated unit testing impractical. Requesting theNo New Testslabel.Release note