Use setenv in qputenv if possible, since it won't leak
putenv(3) is evil: SUSv2 requires that the pointer passed to it be added to the environment and that modifying the contents of that pointer later will also cause the environment to change. That means we needed to strdup before calling it and that memory was never freed. This shows up all the time in valgrind's leak check. Instead, let's use the 4.3BSD & POSIX.1-2001 setenv(3) function, which does copy. That means there are either no leaks or, if there are, they're not our fault. Change-Id: I4576f91cc718b6b3cae790c4f2854c4976dded37 Reviewed-by: Qt Doc Bot <qt_docbot@qt-project.org> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
parent
ecbaa69d71
commit
19fc1de9fc
@ -2165,6 +2165,9 @@ bool qputenv(const char *varName, const QByteArray& value)
|
||||
{
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
return _putenv_s(varName, value.constData()) == 0;
|
||||
#elif defined(_POSIX_VERSION) && (_POSIX_VERSION-0) >= 200112L
|
||||
// POSIX.1-2001 has setenv
|
||||
return setenv(varName, value.constData(), true) == 0;
|
||||
#else
|
||||
QByteArray buffer(varName);
|
||||
buffer += '=';
|
||||
|
Loading…
Reference in New Issue
Block a user