Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open-uri: Close fd after opening dir or file #530

Merged
merged 4 commits into from
Oct 21, 2020

Conversation

hadess
Copy link
Contributor

@hadess hadess commented Sep 23, 2020

Use new XdpFd type with g_auto to make sure the file descriptor gets
closed when the function finishes.

@@ -586,7 +586,7 @@ handle_open_in_thread_func (GTask *task,
gboolean ask_for_content_type;
GVariantBuilder opts_builder;
gboolean skip_app_chooser = FALSE;
int fd;
g_auto(XdpFd) fd = -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

I was looking through the post-1.8.0 changes in the repo, and this change looked a bit suspect.

In particular, this function still has a close(fd) call buried in its body, so the destructor will sometimes call close() on a stale (or reallocated) file descriptor. Might it be better to manage the lifetime by storing the fd with g_object_set_data_full() with an appropriate destroy_notify function (i.e. something that calls close() on values >= 0).

@TingPing TingPing deleted the wip/hadess/more-fd-closing branch September 19, 2021 15:22
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.

3 participants