summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-06-12 15:56:03 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-06-12 16:19:37 (GMT)
commit2f4ca8e06be0477503acf2a4bf38a1c76f52e5b1 (patch)
treef310e3a0ee4fee75e70969a8c32043dc0455933d
parentbb55f848ae006664cf2ee0dbe6b96aa0b802093e (diff)
downloadQt-2f4ca8e06be0477503acf2a4bf38a1c76f52e5b1.zip
Qt-2f4ca8e06be0477503acf2a4bf38a1c76f52e5b1.tar.gz
Qt-2f4ca8e06be0477503acf2a4bf38a1c76f52e5b1.tar.bz2
Improved resetting the DESKTOP_STARTUP_ID envvar on X11
We shouldn't put static variable into the environment since it will crash if someone tries to access environment after Qt has been unloaded. Task-number: related to 217782 Reviewed-by: Bradley T. Hughes
-rw-r--r--src/gui/kernel/qapplication_x11.cpp28
-rw-r--r--src/gui/kernel/qt_x11_p.h1
2 files changed, 23 insertions, 6 deletions
diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp
index a94347b..7387fb0 100644
--- a/src/gui/kernel/qapplication_x11.cpp
+++ b/src/gui/kernel/qapplication_x11.cpp
@@ -128,6 +128,10 @@ extern "C" {
#include <private/qbackingstore_p.h>
+#if defined(Q_OS_BSD4) || _POSIX_VERSION+0 < 200112L
+# define QT_NO_UNSETENV
+#endif
+
QT_BEGIN_NAMESPACE
//#define X_NOT_BROKEN
@@ -1757,7 +1761,7 @@ void qt_init(QApplicationPrivate *priv, int,
X11->pattern_fills[i].screen = -1;
#endif
- X11->startupId = X11->originalStartupId = 0;
+ X11->startupId = X11->originalStartupId = X11->startupIdString = 0;
int argc = priv->argc;
char **argv = priv->argv;
@@ -2556,9 +2560,16 @@ void qt_init(QApplicationPrivate *priv, int,
X11->startupId = getenv("DESKTOP_STARTUP_ID");
X11->originalStartupId = X11->startupId;
- static char desktop_startup_id[] = "DESKTOP_STARTUP_ID=";
- putenv(desktop_startup_id);
-
+ if (X11->startupId) {
+#ifndef QT_NO_UNSETENV
+ unsetenv("DESKTOP_STARTUP_ID");
+#else
+ // it's a small memory leak, however we won't crash if Qt is
+ // unloaded and someones tries to use the envoriment.
+ X11->startupIdString = strdup("DESKTOP_STARTUP_ID=");
+ putenv(X11->startupIdString);
+#endif
+ }
} else {
// read some non-GUI settings when not using the X server...
@@ -2690,9 +2701,14 @@ void qt_cleanup()
#endif
}
- // restore original value back. This is also done in QWidgetPrivate::show_sys.
- if (X11->originalStartupId)
+#ifdef QT_NO_UNSETENV
+ // restore original value back.
+ if (X11->originalStartupId && X11->startupIdString) {
putenv(X11->originalStartupId);
+ free(X11->startupIdString);
+ X11->startupIdString = 0;
+ }
+#endif
#ifndef QT_NO_XRENDER
for (int i = 0; i < X11->solid_fill_count; ++i) {
diff --git a/src/gui/kernel/qt_x11_p.h b/src/gui/kernel/qt_x11_p.h
index 21bb550..b480f34 100644
--- a/src/gui/kernel/qt_x11_p.h
+++ b/src/gui/kernel/qt_x11_p.h
@@ -507,6 +507,7 @@ struct QX11Data
char *startupId;
char *originalStartupId;
+ char *startupIdString;
DesktopEnvironment desktopEnvironment;