From 2f4ca8e06be0477503acf2a4bf38a1c76f52e5b1 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Fri, 12 Jun 2009 17:56:03 +0200 Subject: 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 --- src/gui/kernel/qapplication_x11.cpp | 28 ++++++++++++++++++++++------ src/gui/kernel/qt_x11_p.h | 1 + 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 +#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; -- cgit v0.12