This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.
Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
> 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>
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |