From 00a3a436d061fc5fd9503fb210e37247f6cfaad3 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann <sebholt@xwmw.org> Date: Sun, 14 Apr 2019 16:55:33 +0200 Subject: [PATCH] SystemTools: Update buffered env value string only on a change In `SystemToolsStatic::GetEnvBuffered` a pointer to the data of an internal `std::string` is returned. This string should only be updated on a change to keep already emitted pointers valid as long as possible. --- SystemTools.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SystemTools.cxx b/SystemTools.cxx index 87da80e..6773771 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -623,7 +623,9 @@ const char* SystemToolsStatic::GetEnvBuffered(const char* key) std::string env; if (SystemTools::GetEnv(key, env)) { std::string& menv = SystemTools::Statics->EnvMap[key]; - menv = std::move(env); + if (menv != env) { + menv = std::move(env); + } return menv.c_str(); } return KWSYS_NULLPTR; -- GitLab