mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-07 12:32:26 +00:00
fix memory leak
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21898 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b5158fbe51
commit
1afafb9d5b
@ -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 @@ 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<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;
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user