Setenv/putenv changes break existing code.
Geoff Keating
geoffk@ozemail.com.au
Mon Aug 2 18:48:00 GMT 1999
> Date: Mon, 2 Aug 1999 18:00:00 -0700 (PDT)
> From: hjl@lucon.org (H.J. Lu)
> The recent setenv/putenv change break existing code like:
>
> p = malloc (100);
> .....
> putenv (p);
> free (p);
>
> sice p is used directly in putenv. However, from the Unix standard:
>
> The putenv() function uses the string argument to set environment
> variable values. The string argument should point to a string of the
> form "name=value". The putenv() function makes the value of the
> environment variable name equal to value by altering an existing
> variable or creating a new one. In either case, the string pointed to
> by string becomes part of the environment, so altering the string will
> change the environment. The space used by string is no longer used
> once a new string-defining name is passed to putenv().
>
> It seems to me that it is ok to free 'p' since it is no longer used
> when returning from putenv ().
Surely freeing 'p' counts as altering *p? And altering it "will
change the environment."
The last sentence means that if you do
p = malloc(100);
strcpy (p, "NAME=value");
putenv (p);
putenv ("NAME=some_other_value");
_now_ you can free `p', because you have redefined `NAME'.
--
Geoffrey Keating <geoffk@cygnus.com>
More information about the Libc-hacker
mailing list