> The problem with putenv() is that it does not copy the supplied string, it just puts a pointer to it into the environment.
"Thus, it is an error is to call putenv() with an automatic variable as the argument, then return from the calling function while string is still part of the environment." [1] Which is exactly what the posted code is doing.
Cheers,
V.