apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Poirier <poir...@pobox.com>
Subject Re: apr_env_set use of putenv
Date Fri, 23 Apr 2010 12:33:07 GMT
On 2010-04-22 at 19:18, Ed Holyat <eholyat@olf.com> wrote:

> - Windows automatically copies and controls the memory with _putenv,
> allocating a copy on Windows should not be done.
>
> - Unix requires a memory allocation, you can free the memory in the
> environment if you clear the environment variable.
>
> e.g.  UNIX
>
> mymem=strdup("FOO=abc");
> putenv(mymem);
> putenv("FOO=");
> free(mymem);
>
> In my opinion it is not worth the coding effort to keep track of the
> environment variables you set and then freeing them.  Environment
> variables should be set once and used for the life of the program they
> are not meant to be set and unset over and over again.  UNIX should
> just be putenv(strdup("FOO=abc"));//set it and forget it.

Another factor to consider - this is only an issue on systems that don't
have setenv().  setenv() is in POSIX and the single Unix Spec v3, so the
number of systems this would affect is likely a minority, and getting
smaller each year.

Dan


Mime
View raw message