Skip to content

fix: close fd on mmap failure in CreateShmBuffer#2095

Open
MrMartyK wants to merge 1 commit into
ValveSoftware:masterfrom
MrMartyK:fix/fd-leak-createshmbuffer
Open

fix: close fd on mmap failure in CreateShmBuffer#2095
MrMartyK wants to merge 1 commit into
ValveSoftware:masterfrom
MrMartyK:fix/fd-leak-createshmbuffer

Conversation

@MrMartyK
Copy link
Copy Markdown

The ftruncate error path closes the fd, but the mmap error path doesn't. This leaks the fd (and the backing tmpfs pages, since the file is already unlinked).

@oSoMoN
Copy link
Copy Markdown

oSoMoN commented Apr 29, 2026

The fd can be closed regardless of the return value of mmap. From the man page:

After the mmap() call has returned, the file descriptor, fd, can be closed immediately without invalidating the mapping.

Note that there is one other place in the code base where a file descriptor isn't closed after being successfully mmapped (in stream_handle_add_buffer() in src/pipewire.cpp).

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