If you free the string, it will cause the environment variable unavailable.
 More details please see the following text extracted from manual of
"putenv":

       The  libc4  and  libc5  and  glibc 2.1.2 versions conform to SUSv2:
the pointer string given to putenv() is used.  In particular, this
       string becomes part of the environment; changing it later will
change 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.)  However,
       glibc 2.0-2.1.1 differs: a copy of the string is used.  On the one
hand this causes a memory leak, and on the other hand  it  violates
       SUSv2.  This has been fixed in glibc 2.1.2.


2011/11/24 Zhi Hui Li <zhihu...@linux.vnet.ibm.com>

> string is allocated by g_malloc, will not be used after putenv, should be
> free before return.
>
> Signed-off-by: Li Zhi Hui <zhihu...@linux.vnet.ibm.com>
> ---
>  os-win32.c |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
>
> diff --git a/os-win32.c b/os-win32.c
> index 8ad5fa1..e6e9143 100644
> --- a/os-win32.c
> +++ b/os-win32.c
> @@ -44,6 +44,7 @@ int setenv(const char *name, const char *value, int
> overwrite)
>          char *string = g_malloc(length);
>          snprintf(string, length, "%s=%s", name, value);
>          result = putenv(string);
> +        g_free(string);
>      }
>      return result;
>  }
> --
> 1.7.4.1
>
>
>

Reply via email to