Skip to content

Conversation

@yuki0iq
Copy link

@yuki0iq yuki0iq commented Nov 21, 2025

Error::new allocates memory (see rust-lang/rust#148971). This is bad in multi-threaded programs, which snug AFAIK is. If the fork occurs while the allocator lock is held by another thread, deadlocks can occur, since there's no one left in the new process to unlock the mutex. I do not believe this is UB, and modern libc offer protections against this issue, but this isn't POSIX-compliant and should preferably be avoided.

nix provides a non-allocating impl From<nix::Error> for std::io::Error, use it instead. This also ensures the correct error code is forwarded to the parent process, instead of the default -EINVAL.

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