From: Alex Rousskov Date: Mon, 2 Jun 2014 06:23:12 +0000 (-0700) Subject: Reduce cache_effective_user was leaking $HOME memory X-Git-Tag: SQUID_3_5_0_1~210 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=96b9d9627bdbe04e16c0a21956a7533223dc2be5;p=thirdparty%2Fsquid.git Reduce cache_effective_user was leaking $HOME memory putenv() leaks memory by design but there is no need to use it at all when the path is unchanged. --- diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 95bea4b0eb..4899fb583b 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -892,16 +892,18 @@ configDoConfigure(void) Config2.effectiveGroupID = pwd->pw_gid; #if HAVE_PUTENV - if (pwd->pw_dir && *pwd->pw_dir) { - int len; - char *env_str = (char *)xcalloc((len = strlen(pwd->pw_dir) + 6), 1); - snprintf(env_str, len, "HOME=%s", pwd->pw_dir); - putenv(env_str); + // putenv() leaks by design; avoid leaks when nothing changes + static SBuf lastDir; + if (lastDir.isEmpty() || !lastDir.cmp(pwd->pw_dir)) { + lastDir = pwd->pw_dir; + int len = strlen(pwd->pw_dir) + 6; + char *env_str = (char *)xcalloc(len, 1); + snprintf(env_str, len, "HOME=%s", pwd->pw_dir); + putenv(env_str); + } } - #endif - } } else { Config2.effectiveUserID = geteuid();