Skip to content

Comments

cloned_binary: do not close file descriptor twice#2014

Merged
giuseppe merged 1 commit intocontainers:mainfrom
eriksjolund:do-not-close-twice
Feb 19, 2026
Merged

cloned_binary: do not close file descriptor twice#2014
giuseppe merged 1 commit intocontainers:mainfrom
eriksjolund:do-not-close-twice

Conversation

@eriksjolund
Copy link
Contributor

Closes: #2013

@gemini-code-assist
Copy link

Summary of Changes

Hello @eriksjolund, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug related to file descriptor handling within the clone_binary function. By refactoring the scope of a specific file descriptor, it prevents a double-close scenario that could cause instability or incorrect resource management. The change ensures that file descriptors are properly closed exactly once, improving the robustness of the binary cloning process.

Highlights

  • File Descriptor Management: The binfd file descriptor, used for reading the current binary, was previously declared at the function scope with cleanup_close, leading to an implicit close. An explicit close(binfd) call was also present, causing a double-close issue.
  • Scope Refactoring: The declaration of binfd has been moved into a new inner block scope. This ensures that the cleanup_close attribute correctly closes the file descriptor when execution leaves that specific block, eliminating the need for an explicit close() call and preventing the double-close.
  • Bug Fix: This change resolves a bug where the binfd file descriptor could be closed twice, which could lead to undefined behavior or errors in the cloned_binary function.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/libcrun/cloned_binary.c
    • Removed the cleanup_close int binfd = -1; declaration from the main function scope.
    • Introduced a new inner block scope for binfd declaration, ensuring cleanup_close applies correctly.
    • Removed the explicit close(binfd); call, as it is now handled by the cleanup_close attribute upon exiting the new scope.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly resolves a double-close issue with a file descriptor by reducing the scope of the binfd variable and relying on the cleanup_close attribute for proper resource management. The change is logical and improves the robustness of the code. I have one minor suggestion regarding code style.

Closes: containers#2013

Signed-off-by: Erik Sjölund <erik.sjolund@gmail.com>
@packit-as-a-service
Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

@packit-as-a-service
Copy link

TMT tests failed. @containers/packit-build please check.

if (sent != statbuf.st_size)
goto error;

if (seal_execfd(&execfd, fdtype) < 0)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we can call seal if there is an open fd.

It is safer to do:

close(binfd);
binfd = -1;

Copy link
Member

Choose a reason for hiding this comment

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

nevermind, I said something silly.

That is not a problem (and different fd)

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

LGTM

@giuseppe giuseppe merged commit e954750 into containers:main Feb 19, 2026
45 of 47 checks passed
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.

file descriptor closed twice in cloned_binary()

2 participants