4 ms·
In my experience, because it is documented that’s the behavior I would expect. That being said, I went to look[0] and it turns out it wasn’t a lie. [0]https:/
by tjfontaine 3y ago
In my experience, because it is documented that’s the behavior I would expect.
That being said, I went to look[0] and it turns out it wasn’t a lie.
[0]https://github.com/illumos/illumos-gate/blob/master/usr/src/lib/libc/port/gen/getenv.c https://github.com/illumos/illumos-gate/blob/master/usr/src/...
- hddqsb 3y agoFor the curious: They make getenv() thread-safe by intentionally leaking the old environment, which they argue is acceptable because the memory leak is bounded to 3x the space actually needed. The getenv/setenv/putenv/environ API looks terrible on closer inspection -- it does not appear possible for an implementation to be safe, leak-free, and efficient.
- o11c 3y agoJust because they use locks doesn't mean it's automatically actually thread-safe. The comment about "this is safe for people walking `environ`" is definitely a lie, for example, though the bug might be hidden on some common architectures with popular compilers in their default configuration.