Skip to content

Fix file descriptor leak in get_binary_hash #2507

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

Merged
merged 1 commit into from
Jul 26, 2025

Conversation

lhywk
Copy link

@lhywk lhywk commented Jul 26, 2025

Describe

This patch fixes a file descriptor leak in the get_binary_hash() function.
When the target file is empty (st.st_size == 0), the function previously returned early without closing the file descriptor, resulting in a potential resource leak.
The fix adds a close(fd) call before returning in that case.

Expected Behavior

When the input file is empty, the function should close the file descriptor before returning.
This ensures no file descriptor leak occurs regardless of file contents.

Actual Behavior

If the input file is empty, the function returns immediately without closing the file descriptor.
When invoked repeatedly, this can lead to file descriptor exhaustion and undefined behavior.

Prevents a file descriptor leak by ensuring the descriptor is closed when handling empty files.
Thanks for reviewing.

@vanhauser-thc vanhauser-thc changed the base branch from stable to dev July 26, 2025 09:59
@vanhauser-thc
Copy link
Member

Thanks. Please direct all PRs to the dev branch

@vanhauser-thc vanhauser-thc merged commit 7e63f23 into AFLplusplus:dev Jul 26, 2025
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