From: wessels <> Date: Sat, 5 Nov 2005 04:02:15 +0000 (+0000) Subject: parse_date() is one most frequent users of malloc (strdup() actually). X-Git-Tag: SQUID_3_0_PRE4~548 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a69938aefee5ddd49aa2dbf71a750894832267f4;p=thirdparty%2Fsquid.git parse_date() is one most frequent users of malloc (strdup() actually). I think it makes sense to replace it with a static buffer and just call xstrncpy(). --- diff --git a/lib/rfc1123.c b/lib/rfc1123.c index 6ea50f7ad4..7308332353 100644 --- a/lib/rfc1123.c +++ b/lib/rfc1123.c @@ -1,6 +1,6 @@ /* - * $Id: rfc1123.c,v 1.35 2005/07/03 15:25:07 serassio Exp $ + * $Id: rfc1123.c,v 1.36 2005/11/04 21:02:15 wessels Exp $ * * DEBUG: * AUTHOR: Harvest Derived @@ -161,7 +161,7 @@ static struct tm * parse_date(const char *str) { struct tm *tm; - char *tmp = xstrdup(str); + static char tmp[64]; char *t; char *wday = NULL; char *day = NULL; @@ -170,6 +170,8 @@ parse_date(const char *str) char *time = NULL; char *zone = NULL; + xstrncpy(tmp, str, 64); + for (t = strtok(tmp, ", "); t; t = strtok(NULL, ", ")) { if (xisdigit(*t)) { if (!day) { @@ -197,7 +199,6 @@ parse_date(const char *str) } tm = parse_date_elements(day, month, year, time, zone); - xfree(tmp); return tm; }