getdate: don't leak when TZ contains two or more '"'s
authorJim Meyering <meyering@redhat.com>
Mon, 18 Jan 2010 07:23:24 +0000 (08:23 +0100)
committerJim Meyering <meyering@redhat.com>
Mon, 18 Jan 2010 07:23:24 +0000 (08:23 +0100)
* lib/getdate.y (get_date): Don't leak a copy of TZ for each
double quote in TZ after the first one.

ChangeLog
lib/getdate.y

index 42257ee2f46782f26690eb42711eb5b509d393ca..7171d59c74239e64ed07d5782c55b3b9c1a169b9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2010-01-18  Jim Meyering  <meyering@redhat.com>
 
+       getdate: don't leak when TZ contains two or more '"'s
+       * lib/getdate.y (get_date): Don't leak a copy of TZ for each
+       double quote in TZ after the first one.
+
        readtokens: do not leak internal token_lengths buffer
        * lib/readtokens.c (readtokens): Free the local, lengths,
        when the supplied "token_lengths" parameter is NULL.
index e8c523358847eea43d894553744c5333f15e6510..445865bdb839ebbe2f3c9e44e94c6182daaeb453 100644 (file)
@@ -1252,6 +1252,8 @@ get_date (struct timespec *result, char const *p, struct timespec const *now)
             char tz1buf[TZBUFSIZE];
             bool large_tz = TZBUFSIZE < tzsize;
             bool setenv_ok;
+            /* Free tz0, in case this is the 2nd or subsequent time through. */
+            free (tz0);
             tz0 = get_tz (tz0buf);
             z = tz1 = large_tz ? xmalloc (tzsize) : tz1buf;
             for (s = tzbase; *s != '"'; s++)