summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qglobal.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-09-07 16:13:36 +0200
committerQt by Nokia <qt-info@nokia.com>2012-09-07 18:41:22 +0200
commit19fc1de9fc5fda0db672231785bea3f3ae098fca (patch)
tree77a8286189f2b2c6efd50506079f5028fdc3a5b0 /src/corelib/global/qglobal.cpp
parentecbaa69d71992e6447df7b40b0c4e0dc6f255654 (diff)
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>
Diffstat (limited to 'src/corelib/global/qglobal.cpp')
-rw-r--r--src/corelib/global/qglobal.cpp3
1 files changed, 3 insertions, 0 deletions
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 += '=';