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

Shared file descriptor is closed prematurely #44

Closed
josephlr opened this issue Jun 28, 2019 · 1 comment · Fixed by #45
Closed

Shared file descriptor is closed prematurely #44

josephlr opened this issue Jun 28, 2019 · 1 comment · Fixed by #45

Comments

@josephlr
Copy link
Member

Here, we create a File from a raw fd. However, as this object is created on the stack, at the endo the function, the file will be dropped, and thus closed.

This means that on systems using a shared FD, the second call to getrandom will fail. This can be fixed by just storing a File instead of a RawFd in static memory.

@newpavlov
Copy link
Member

Yes, code should use mem::forget(f), I was doing it, but missed it during review...

You can't store File, as Read impl requires an exclusive access. You could use try_clone, but I think it will be slightly less efficient.

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 a pull request may close this issue.

2 participants