Skip to content

fix(unshare): close pidfd after setns#90

Draft
noeljackson wants to merge 1 commit intoedera-dev:mainfrom
noeljackson:fix/pidfd-leak
Draft

fix(unshare): close pidfd after setns#90
noeljackson wants to merge 1 commit intoedera-dev:mainfrom
noeljackson:fix/pidfd-leak

Conversation

@noeljackson
Copy link

Summary

Fix a file descriptor leak in setns(): the pidfd obtained from pidfd_open() was never closed after being passed to setns(2).

Each call to setns() leaked one file descriptor. In long-running processes that attach to containers repeatedly (e.g. exec into a container), this would eventually exhaust the fd limit.

The fix captures the setns result, unconditionally closes the pidfd via libc::close(), then returns the result. The close happens regardless of whether setns succeeded or failed.

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.

1 participant