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

[Bug] File Descriptor Leak in rdb.c #1313

Open
oilfacer opened this issue Nov 15, 2024 · 2 comments
Open

[Bug] File Descriptor Leak in rdb.c #1313

oilfacer opened this issue Nov 15, 2024 · 2 comments

Comments

@oilfacer
Copy link

I hope this message finds you well. I have identified a potential "File Descriptor Leak" issue in the project, and I would like to bring it to your attention as it may impact resource management and stability. This issue could lead to resource exhaustion if not addressed, as the file descriptor is left open without being properly released. Could you please help me check it? Thank you for your effort and patience!
Issue Description:
The bug is located in the file src/rdb.c, within the rdbRemoveTempFile function. The specific code flow is as follows:
On line 1648, a file descriptor fd is created by calling the open function with the parameters O_RDONLY | O_NONBLOCK.
After this file descriptor is created, it is marked as unused with UNUSED(fd); but is not explicitly closed before the function returns.
This omission leads to a "File Descriptor Leak" issue, as the descriptor remains open until the process exits, causing potential resource management problems if this function is called multiple times.
1731678208244

@hpatro
Copy link
Contributor

hpatro commented Nov 15, 2024

Haven't read the code, but the comment above that indicates that the file descriptor would get released as part of the exit of the child process created for background save. @oilfacer Did you face any particular issue with leaking fd ?

@zuiderkwast
Copy link
Contributor

As the code comment explains, this fd is leaked on purpose, and only when called by a signal handler. In this case, the process is about to exit soon.

A file is opened and then unlinked. The leaked fd prevents the file from being deleted until the process exits.

Did you find this using some tool or sratic analysis? Can we make it even more clear that is intentional?

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

No branches or pull requests

3 participants