From ac56ed7981bc727355fcc33a49a6e3138ee24f29 Mon Sep 17 00:00:00 2001 From: Alex Rousskov Date: Fri, 23 Sep 2016 23:11:48 +1200 Subject: [PATCH] Do reset $HOME if needed after r13435. Minimize putenv() memory leaks. While r13435 is attributed to me, the wrong condition was not mine. This is a good example of why "cmp() op 0" pattern is usually safer because the "==" or "!=" operator "tells" us whether the strings are equal, unlike "!cmp()" that is often misread as "not equal". --- src/cache_cf.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cache_cf.cc b/src/cache_cf.cc index fedabc04be..630f3e9786 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -849,7 +849,7 @@ configDoConfigure(void) if (pwd->pw_dir && *pwd->pw_dir) { // putenv() leaks by design; avoid leaks when nothing changes static SBuf lastDir; - if (lastDir.isEmpty() || !lastDir.cmp(pwd->pw_dir)) { + if (lastDir.isEmpty() || lastDir.cmp(pwd->pw_dir) != 0) { lastDir = pwd->pw_dir; int len = strlen(pwd->pw_dir) + 6; char *env_str = (char *)xcalloc(len, 1); -- 2.47.2