From 19fc1de9fc5fda0db672231785bea3f3ae098fca Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 7 Sep 2012 16:13:36 +0200 Subject: [PATCH] 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 Reviewed-by: Giuseppe D'Angelo --- src/corelib/global/qglobal.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index e1eb2736c2..df4eb0ecf4 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -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 += '=';