From mboxrd@z Thu Jan 1 00:00:00 1970 From: Geoff Keating To: hjl@lucon.org Cc: libc-hacker@sourceware.cygnus.com Subject: Re: Setenv/putenv changes break existing code. Date: Mon, 02 Aug 1999 18:48:00 -0000 Message-id: <199908030123.LAA00651@gluttony.geoffk.wattle.id.au> References: <19990803010000.E96D457BA@ocean.lucon.org> X-SW-Source: 1999-08/msg00007.html > 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