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.
Just using a
RwLock
to protectgetenv
/setenv
/etc. isn't sufficient becausegetenv
returns a pointer to memory which needs to remain valid beyond thegetenv
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.