3 ms·
> FreeBSD libc does similar with getenv, in that the returned environment is a snapshot of that point in time. How does FreeBSD's libc know when to free that s
by deathanatos 10y ago
> FreeBSD libc does similar with getenv, in that the returned environment is a snapshot of that point in time.
How does FreeBSD's libc know when to free that snapshot? (Since there is no "free the env snapshot you gave me" call.) If thread B calls getenv, how does that not invalidate the snapshot that thread A has?
- MaulingMonkey 10y agoThread local storage would let you store a snapshot for thread A until thread A itself re-invokes getenv. Other comments seem to imply this isn't what FreeBSD is doing however.
- quotemstr 10y agoSo what if you call getenv twice? const char* foo = getenv("FOO"); const char* bar = getenv("BAR"); foo and bar should both be valid here. Sure, you could allocate an arbitrary amount of thread-local storage, but that's still a leak.
- MaulingMonkey 10y agoGuess there's a reason FreeBSD isn't doing it :D.