mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 02:14:50 +00:00
fix putenv memory leak
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8037 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
db78dbfa04
commit
dffbeaf18d
@ -1,3 +1,10 @@
|
||||
2003-11-05 João Luis M. Assirati <assirati@fma.if.usp.br>
|
||||
|
||||
* putenv.C: allocate the string before putting it into the
|
||||
environment.
|
||||
|
||||
* lyxlib.h: adjust.
|
||||
|
||||
2003-11-03 Lars Gullik Bjønnes <larsbj@gullik.net>
|
||||
|
||||
* tempname.C (tempName): use scoped_array for exception safety
|
||||
|
@ -40,8 +40,8 @@ int kill(int pid, int sig);
|
||||
void abort();
|
||||
/// create the given directory with the given mode
|
||||
int mkdir(std::string const & pathname, unsigned long int mode);
|
||||
/// put a C std::string into the environment
|
||||
int putenv(char const * str);
|
||||
/// put variable=value as a C std::string into the environment
|
||||
bool putenv(std::string const & varname, std::string const & value);
|
||||
/// unlink the given file
|
||||
int unlink(std::string const & file);
|
||||
/// remove the given directory
|
||||
|
@ -4,6 +4,7 @@
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Lars Gullik Bjønnes
|
||||
* \author João Luis M. Assirati
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
@ -13,8 +14,25 @@
|
||||
#include "lyxlib.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
int lyx::support::putenv(char const * str)
|
||||
using std::string;
|
||||
using std::map;
|
||||
|
||||
bool lyx::support::putenv(string const & varname, string const & value)
|
||||
{
|
||||
return ::putenv(const_cast<char*>(str));
|
||||
static map<string, char *> varmap;
|
||||
|
||||
string str = varname + '=' + value;
|
||||
char * newptr = new char[str.size() + 1];
|
||||
newptr[str.copy(newptr, string::npos)] = '\0';
|
||||
bool status = (::putenv(newptr) == 0);
|
||||
|
||||
char * oldptr = varmap[varname];
|
||||
if (oldptr)
|
||||
delete oldptr;
|
||||
varmap[varname] = newptr;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user