On Mon, Sep 30, 2002 at 10:00:54AM +0400, Alexander V. Lukyanov wrote:
> linux man page on putenv clarifies that. It says that glibc 2.0-2.1.1
> used a copy of the string to put into environment, which caused memory
> leak and violated SUSv2; it was fixed in glibc 2.1.2.
> 
> As a workaround an extra putenv can help, but it does not solve memory leak.

Gek, I figured it out.  You unsetenv(), and then the next time it's
called, it just changes the static and returns, thinking it was still in
the environment (but it's not, since the last call unsetenv()'d it.)

-- 
Glenn Maynard
Index: misc.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/misc.cc,v
retrieving revision 1.56
diff -u -r1.56 misc.cc
--- misc.cc     2002/08/05 08:51:14     1.56
+++ misc.cc     2002/09/30 07:09:39
@@ -524,13 +524,21 @@
 
 static void set_tz(const char *tz)
 {
+   static char *put_tz;
+   static int put_tz_alloc;
+
    if(!tz)
    {
       unsetenv("TZ");
+
+      xfree(put_tz);
+      put_tz=0;
+      put_tz_alloc=0;
+
+      tzset();
       return;
    }
-   static char *put_tz;
-   static int put_tz_alloc;
+
    int tz_len=strlen(tz)+4;
    char *new_tz=put_tz;
    if(tz_len>put_tz_alloc)
@@ -542,6 +550,8 @@
       xfree(put_tz);
       put_tz=new_tz;
    }
+   // now initialize libc variables from env TZ.
+   tzset();
 }
 static char *saved_tz=0;
 static void save_tz()

Reply via email to