Andre Poenitz wrote:
On Sat, Dec 01, 2007 at 10:52:52AM -0000, [EMAIL PROTECTED] wrote:
Author: kuemmel
Date: Sat Dec  1 11:52:52 2007
New Revision: 21898

URL: http://www.lyx.org/trac/changeset/21898
Log:
fix memory leak

Modified:
    lyx-devel/trunk/src/support/environment.cpp

Modified: lyx-devel/trunk/src/support/environment.cpp
URL: 
http://www.lyx.org/trac/file/lyx-devel/trunk/src/support/environment.cpp?rev=21898
==============================================================================
--- lyx-devel/trunk/src/support/environment.cpp (original)
+++ lyx-devel/trunk/src/support/environment.cpp Sat Dec  1 11:52:52 2007
@@ -18,6 +18,7 @@
 #include "support/os.h"
#include <boost/tokenizer.hpp>
+#include <boost/shared_array.hpp>
#include <cstdlib>
 #include <map>
@@ -65,22 +66,17 @@
        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<string, char *> varmap;
+       static std::map<string, boost::shared_array<char> > 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<char> newptr(new char[envstr.size() + 1]);
+       envstr.copy(newptr.get(), envstr.length());
+       newptr.get()[envstr.length()] = '\0';
+       bool const retval = ::putenv(newptr.get()) == 0;

Out of curiosity: Is that conceptionally different from a std::string?

Andre'


I also wondered why std::string is not used, but I wanna touch this function
as little as possible, maybe there was a good (?) reason not to use std::string.

Peter

--
Peter Kümmel

Reply via email to