From c1a2b4655331bbbea84531077f00c72d08599638 Mon Sep 17 00:00:00 2001 From: Jens Granseuer Date: Wed, 23 May 2007 17:30:07 +0000 Subject: [PATCH] make sure we always return a copy of the window manager name, not a static 2007-05-23 Jens Granseuer * wm-common.c: (wm_common_get_current_window_manager): make sure we always return a copy of the window manager name, not a static string (fixes bug #439244) svn path=/trunk/; revision=7650 --- capplets/common/ChangeLog | 6 ++++++ capplets/common/wm-common.c | 33 +++++++++++++-------------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/capplets/common/ChangeLog b/capplets/common/ChangeLog index 4131cc691..bb79b758e 100644 --- a/capplets/common/ChangeLog +++ b/capplets/common/ChangeLog @@ -1,3 +1,9 @@ +2007-05-23 Jens Granseuer + + * wm-common.c: (wm_common_get_current_window_manager): make sure we + always return a copy of the window manager name, not a static string + (fixes bug #439244) + 2007-05-19 Jens Granseuer * gconf-property-editor.c: (peditor_tree_view_widget_changed): diff --git a/capplets/common/wm-common.c b/capplets/common/wm-common.c index c8ddf462d..61b1a4d1c 100644 --- a/capplets/common/wm-common.c +++ b/capplets/common/wm-common.c @@ -27,42 +27,35 @@ wm_common_get_current_window_manager (void) guchar *val; if (wm_window == None) - return WM_COMMON_UNKNOWN; + return g_strdup (WM_COMMON_UNKNOWN); utf8_string = XInternAtom (GDK_DISPLAY (), "UTF8_STRING", False); atom = XInternAtom (GDK_DISPLAY (), "_NET_WM_NAME", False); gdk_error_trap_push (); + val = NULL; result = XGetWindowProperty (GDK_DISPLAY (), wm_window, atom, 0, G_MAXLONG, False, utf8_string, &type, &format, &nitems, - &bytes_after, (guchar **)&val); + &bytes_after, &val); - if (gdk_error_trap_pop () || result != Success) - return WM_COMMON_UNKNOWN; - - if (type != utf8_string || - format !=8 || - nitems == 0) + if (gdk_error_trap_pop () || result != Success || + type != utf8_string || format != 8 || nitems == 0 || + !g_utf8_validate (val, nitems, NULL)) { - if (val) - XFree (val); - return WM_COMMON_UNKNOWN; + retval = g_strdup (WM_COMMON_UNKNOWN); + } + else + { + retval = g_strndup (val, nitems); } - if (!g_utf8_validate (val, nitems, NULL)) - { - XFree (val); - return WM_COMMON_UNKNOWN; - } - - retval = g_strndup (val, nitems); - - XFree (val); + if (val) + XFree (val); return retval; }