ipc, conn: resource-leak close file descriptors on error paths#147
Open
fereidani wants to merge 4 commits into
Open
ipc, conn: resource-leak close file descriptors on error paths#147fereidani wants to merge 4 commits into
fereidani wants to merge 4 commits into
Conversation
UAPIOpen dials the socket only to check whether it is in use, but it left the established connection open, leaking a file descriptor on every attempt that found the socket busy. Signed-off-by: Khashayar Fereidani <info@fereidani.com>
If listener.File() returns an error, the underlying unix listener is left open, leaking its file descriptor. Close it on the failure path. Signed-off-by: Khashayar Fereidani <info@fereidani.com>
UAPIListen creates a listener from the file descriptor before setting up inotify. If inotify initialization, watch addition, or the rwcancel helper fails, the listener is returned to the caller neither closed nor handed off, leaking its file descriptor. The inotify file descriptor is likewise leaked when watch addition fails. Close them on each path. Signed-off-by: Khashayar Fereidani <info@fereidani.com>
listenNet resolves the local address after opening the socket. If resolution fails, the socket is returned neither closed nor handed off, leaking its file descriptor. Signed-off-by: Khashayar Fereidani <info@fereidani.com>
sasanhb65
approved these changes
Jun 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
I've built a static analyzer for Go called Ghoul, and I ran it against the wireguard-go codebase. It flagged a few error paths where a file descriptor is opened but never closed.
Ghoul reports:
This series closes each leaked descriptor on its error path:
Each fix is focused on a single path and lives in its own commit.