Skip to content

Fix file descriptor leaks in remote import, save, and checkpoint operations#28741

Open
SebTardif wants to merge 1 commit into
containers:mainfrom
SebTardif:fix-remote-fd-leaks
Open

Fix file descriptor leaks in remote import, save, and checkpoint operations#28741
SebTardif wants to merge 1 commit into
containers:mainfrom
SebTardif:fix-remote-fd-leaks

Conversation

@SebTardif
Copy link
Copy Markdown
Contributor

@SebTardif SebTardif commented May 20, 2026

What does this PR do?

Fixes four file descriptor leaks across remote operations and checkpoint:

  1. tunnel/images.go Import: os.Open(opts.Source) opens the import source file but never closes it. Added defer f.Close().

  2. tunnel/images.go Save: For oci-dir/docker-dir formats, a second os.Open(f.Name()) reopens the temp file but the handle is never closed. Added defer f.Close().

  3. bindings/checkpoint.go Restore: os.Open(i) opens the checkpoint archive, but the result is assigned to an io.Reader, hiding the *os.File. Introduced a typed variable with defer Close().

  4. container_internal_common.go exportCheckpoint: Inside a for loop, os.Create() opens a volume tar file. The explicit close at the end is only reached on the happy path; five error returns skip it. Added explicit Close() on each error path.

Same class of bug as #28723 and #28724.

How was this tested?

All fixes are minimal close/defer additions with no behavioral change. go vet and go build pass on all affected packages. The affected remote packages have no existing test files. Requesting No New Tests label.

Does this PR introduce a user-facing change?

No.

NONE

…ations

Fix four file descriptor leaks:

1. tunnel/images.go Import: os.Open(opts.Source) never closed
2. tunnel/images.go Save: second os.Open for oci-dir/docker-dir never closed
3. bindings/checkpoint.go Restore: os.Open(importPath) never closed
4. container_internal_common.go: os.Create in checkpoint volume export
   loop not closed on five error paths

These are the same class of bug fixed in containers#28723 and containers#28724.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>

volume, err := c.runtime.GetVolume(v.Name)
if err != nil {
volumeTarFile.Close()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why shouldnt this be a single deferred close ?

if i != "" {
params.Set("import", "true")
r, err = os.Open(i)
importFile, err := os.Open(i)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idont understand why you are doing this, and then renaming later?

if err != nil {
return nil, err
}
defer f.Close()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

samsies, wouldnt a single defer be better?

@baude
Copy link
Copy Markdown
Member

baude commented May 20, 2026

are you using AI to find these and generate your code and commit messages? remove the origin bits please ... and ptal at https://github.com/containers/podman/blob/main/LLM_POLICY.md

@SebTardif
Copy link
Copy Markdown
Contributor Author

Removed the origin table, apologies for the noise. I did use AI as a tool to help spot these, but I reviewed every fix myself and can speak to each one. I've read the LLM policy. Thanks for pointing it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants