Fix leak in setenvStr, bug184

This commit is contained in:
Wilson Snyder 2010-01-19 12:55:34 -05:00
parent 89e03a86b7
commit 2e9ade61b2

View File

@ -320,15 +320,13 @@ void V3Options::setenvStr(const string& envvar, const string& value, const strin
} else { } else {
UINFO(1,"export "<<envvar<<"="<<value<<endl); UINFO(1,"export "<<envvar<<"="<<value<<endl);
} }
//setenv() replaced by putenv() in MinGW environment. Prototype is different
//putenv() requires NAME=VALUE format
#if !defined (__MINGW32__) #if !defined (__MINGW32__)
setenv(envvar.c_str(),value.c_str(),true); setenv(envvar.c_str(),value.c_str(),true);
#else #else
int len = value.size() + envvar.size() + 5; //setenv() replaced by putenv() in MinGW environment. Prototype is different
char *str = new char[len]; //putenv() requires NAME=VALUE format
sprintf(str,"%s=%s", envvar.c_str(), value.c_str()); string vareq = envvar + "=" + value;
putenv(str); putenv(vareq.c_str());
#endif #endif
} }