Re: clearing the environment
Jorge Almeida <[email protected]> Sun, 3 Jun 2012 13:44:07 +0100
| Newsgroups | gmane.linux.lib.dietlibc |
|---|---|
| Message-ID | <CAKpSnpKFhXVjeb9q=ORey-KrVryzziveuYzfu7W1oUAE0mST0Q@mail.gmail.com> |
On Sun, Jun 3, 2012 at 10:24 AM, Laurent Bercot <[email protected]> wrote: >> So, if I understood right, we shouldn't use clearenv() or equivalent and then >> setup a few variables, but rather build from scratch an array an pass it to >> execve. Is there some issue with clearenv, e.g. related with memory leaking? > > putenv() and friends were made to modify the environment within the same > process, without execve'ing. It requires some hidden memory allocations, > it's inefficient, and unless you're coding a shell, it's mostly useless. > Thanks for the explanation, it's hard to find this kind of stuff in the net. > Since you can afford to execve(), it's much simpler to just setup a new > environment array and pass it to execve(). You *can* use putenv(), or > heap memory allocation, and just not care about memory leaks, since > execve() will clean up everything anyway; but you don't need to - and you > certainly don't need to if all you want is clear the environment. > > Btw, don't pass NULL to execve(). Pass char const *envp[1] = { NULL }. > Actually, I want to clear the environment and then set two variables, so I have a 3 elements array. Cheers Jorge