From 1afafb9d5bd95559fd03db716e6329f79dca2fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20K=C3=BCmmel?= Date: Sat, 1 Dec 2007 10:52:52 +0000 Subject: [PATCH] fix memory leak git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21898 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/support/environment.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/support/environment.cpp b/src/support/environment.cpp index 552f1b0f1f..5bce59916d 100644 --- a/src/support/environment.cpp +++ b/src/support/environment.cpp @@ -18,6 +18,7 @@ #include "support/os.h" #include +#include #include #include @@ -65,22 +66,17 @@ bool setEnv(string const & name, string const & value) string const encoded = to_local8bit(from_utf8(value)); #if defined (HAVE_SETENV) return ::setenv(name.c_str(), encoded.c_str(), true); - #elif defined (HAVE_PUTENV) - static std::map varmap; + static std::map > varmap; string envstr = name + '=' + encoded; - char * newptr = new char[envstr.size() + 1]; - envstr.copy(newptr, envstr.length()); - newptr[envstr.length()] = '\0'; - int const retval = ::putenv(newptr); + boost::shared_array newptr(new char[envstr.size() + 1]); + envstr.copy(newptr.get(), envstr.length()); + newptr.get()[envstr.length()] = '\0'; + bool const retval = ::putenv(newptr.get()) == 0; - char * oldptr = varmap[name]; - if (oldptr) - delete oldptr; varmap[name] = newptr; - return retval == 0; - + return retval; #else #error No environment-setting function has been defined. #endif