sunfishcode / c-ward

An implementation of libc written in Rust
Other
188 stars 11 forks source link

Make environment-variable handling thread-safe by leaking. #66

Closed sunfishcode closed 10 months ago

sunfishcode commented 10 months ago

Just using a RwLock to protect getenv/setenv/etc. isn't sufficient because getenv returns a pointer to memory which needs to remain valid beyond the getenv call, so it isn't covered by the lock.

To fix this, replacing the locking scheme with a leaking scheme: have setenv etc. leak the old memory when installing new environment variables.