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

Are unclosed file descriptors a memory leak? #3771

Open
oli-obk opened this issue Jul 29, 2024 · 3 comments
Open

Are unclosed file descriptors a memory leak? #3771

oli-obk opened this issue Jul 29, 2024 · 3 comments
Labels
A-files Area: related to files, paths, sockets, file descriptors, or handles C-proposal Category: a proposal for something we might want to do, or maybe not; details still being worked out

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Jul 29, 2024

We do not check whether file descriptors got closed before exiting the program.

While it's not wrong per-se, the file descriptors will get closed by the kernel after the program finishes, the same is true for leaked allocations.

Should we report them the same way we report memory leaks? Obviously not for stdin, stdout, and stderr, but for everything else...

@RalfJung
Copy link
Member

RalfJung commented Jul 29, 2024

The flipside is that we have to be careful to not report deliberate leaks. One of the unfortunate side-effects of people getting leak reports from valgrind is that people "fixed" their code by having C++ static variables be freed during program exit which now causes race conditions when one thread calls exit while another thread works on that static... if something truly lives for the entire duration of the program, just leaking it is the best option, better than freeing it at exit.

For memory, we have a bunch of machinery to handle this as good as we can: memory reachable via statics and even main-thread thread-locals is not considered leaking. For file descriptors it seems to be hard to do anything like that, so I am not sure how to best handle this.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 29, 2024

Right. and especially for something like loggers, which live globally, but may have handles to files or even the network, handling that is just going to be a pain. I guess wontfix, but could possibly add an opt-in flag for checking file descriptors just like valgrind has: --track-fds=yes

@RalfJung
Copy link
Member

In that case we'd probably at least want a function like miri_leak_fd to mark an FD as deliberately leaked.

@RalfJung RalfJung added C-proposal Category: a proposal for something we might want to do, or maybe not; details still being worked out A-files Area: related to files, paths, sockets, file descriptors, or handles labels Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-files Area: related to files, paths, sockets, file descriptors, or handles C-proposal Category: a proposal for something we might want to do, or maybe not; details still being worked out
Projects
None yet
Development

No branches or pull requests

2 participants