[Xfce4-commits] [xfce/xfwm4] 01/01: Protect against XErrors

noreply at xfce.org noreply at xfce.org
Sat May 11 18:02:27 CEST 2019


This is an automated email from the git hooks/post-receive script.

o   l   i   v   i   e   r       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/xfwm4.

commit 0bf68c537d72f7d35be6581bb7c91cd5c071777f
Author: Olivier Fourdan <fourdan at xfce.org>
Date:   Sat May 11 17:55:16 2019 +0200

    Protect against XErrors
    
    Places where the window manager uses the client window are all possible
    sources of XError because the window may have vanished and the window
    manager won't know until it gets the destroy notification from the
    Xserver.
    
    As GDK error handler is smart and uses the serial of the requests to
    check for errors, if the XError is not trapped in time it will end up in
    GDK and cause an abort.
    
    Protect against such a possibility by making sure cases where the XID
    of the client or one of its dependent resources is used remains withing
    an error trap/push.
    
    Signed-off-by: Olivier Fourdan <fourdan at xfce.org>
---
 src/client.c     |  19 ++-
 src/compositor.c |  91 ++++++++------
 src/events.c     |   2 +
 src/focus.c      |   9 +-
 src/hints.c      | 360 +++++++++++++++++++++++++++++++++++--------------------
 src/netwm.c      |  14 ++-
 6 files changed, 325 insertions(+), 170 deletions(-)

diff --git a/src/client.c b/src/client.c
index 7bf530e..f2ba129 100644
--- a/src/client.c
+++ b/src/client.c
@@ -644,6 +644,7 @@ clientConfigureWindows (Client *c, XWindowChanges * wc, unsigned long mask, unsi
         change_mask_client |= (CWX | CWY);
     }
 
+    myDisplayErrorTrapPush (display_info);
     if (change_mask_frame & (CWX | CWY | CWWidth | CWHeight))
     {
         change_values.x = frameX (c);
@@ -661,6 +662,7 @@ clientConfigureWindows (Client *c, XWindowChanges * wc, unsigned long mask, unsi
         change_values.height = c->height;
         XConfigureWindow (display_info->dpy, c->window, change_mask_client, &change_values);
     }
+    myDisplayErrorTrapPopIgnored (display_info);
 
     if (WIN_RESIZED)
     {
@@ -672,13 +674,18 @@ void
 clientSendConfigureNotify (Client *c)
 {
     XConfigureEvent ce;
+    DisplayInfo *display_info;
+    ScreenInfo *screen_info;
 
     g_return_if_fail (c != NULL);
     g_return_if_fail (c->window != None);
 
+    screen_info = c->screen_info;
+    display_info = screen_info->display_info;
+
     DBG ("Sending ConfigureNotify");
     ce.type = ConfigureNotify;
-    ce.display = clientGetXDisplay (c);
+    ce.display = display_info->dpy;
     ce.send_event = TRUE;
     ce.event = c->window;
     ce.window = c->window;
@@ -689,8 +696,11 @@ clientSendConfigureNotify (Client *c)
     ce.border_width = 0;
     ce.above = None;
     ce.override_redirect = FALSE;
-    XSendEvent (clientGetXDisplay (c), c->window, TRUE,
+
+    myDisplayErrorTrapPush (display_info);
+    XSendEvent (display_info->dpy, c->window, TRUE,
                 StructureNotifyMask, (XEvent *) & ce);
+    myDisplayErrorTrapPopIgnored (display_info);
 }
 
 void
@@ -1442,6 +1452,7 @@ clientCheckShape (Client *c)
 
     screen_info = c->screen_info;
     display_info = screen_info->display_info;
+    boundingShaped = 0;
 
     if (display_info->have_shape)
     {
@@ -2338,11 +2349,13 @@ clientShowSingle (Client *c, gboolean deiconify)
     {
         TRACE ("showing client \"%s\" (0x%lx)", c->name, c->window);
         FLAG_SET (c->xfwm_flags, XFWM_FLAG_VISIBLE);
+        myDisplayErrorTrapPush (display_info);
         XMapWindow (display_info->dpy, c->frame);
         if (!FLAG_TEST (c->flags, CLIENT_FLAG_SHADED))
         {
             XMapWindow (display_info->dpy, c->window);
         }
+        myDisplayErrorTrapPopIgnored (display_info);
         /* Adjust to urgency state as the window is visible */
         clientUpdateUrgency (c);
     }
@@ -2832,7 +2845,9 @@ clientUnshade (Client *c)
     {
         if (FLAG_TEST (c->xfwm_flags, XFWM_FLAG_VISIBLE))
         {
+            myDisplayErrorTrapPush (display_info);
             XMapWindow (display_info->dpy, c->window);
+            myDisplayErrorTrapPopIgnored (display_info);
         }
         /*
          * Unshading will show the client window, so we need to focus it when unshading.
diff --git a/src/compositor.c b/src/compositor.c
index de5d49e..ca74b3a 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -741,9 +741,13 @@ border_size (CWindow *cw)
 
     screen_info = cw->screen_info;
     display_info = screen_info->display_info;
+    myDisplayErrorTrapPush (display_info);
     border = XFixesCreateRegionFromWindow (display_info->dpy,
                                            cw->id, WindowRegionBounding);
-    g_return_val_if_fail (border != None, None);
+    if ((myDisplayErrorTrapPop (display_info) != Success) || (border == None))
+    {
+        return None;
+    }
     XFixesSetPictureClipRegion (display_info->dpy, cw->picture, 0, 0, border);
     XFixesTranslateRegion (display_info->dpy, border,
                            cw->attr.x + cw->attr.border_width,
@@ -761,6 +765,7 @@ free_win_data (CWindow *cw, gboolean delete)
     screen_info = cw->screen_info;
     display_info = screen_info->display_info;
 
+    myDisplayErrorTrapPush (display_info);
 #if HAVE_NAME_WINDOW_PIXMAP
     if (cw->name_window_pixmap)
     {
@@ -819,7 +824,6 @@ free_win_data (CWindow *cw, gboolean delete)
 
     if (delete)
     {
-        myDisplayErrorTrapPush (display_info);
         if (cw->picture)
         {
             XRenderFreePicture (display_info->dpy, cw->picture);
@@ -837,7 +841,6 @@ free_win_data (CWindow *cw, gboolean delete)
             XDamageDestroy (display_info->dpy, cw->damage);
             cw->damage = None;
         }
-        myDisplayErrorTrapPopIgnored (display_info);
 
         g_free (cw);
     }
@@ -850,6 +853,7 @@ free_win_data (CWindow *cw, gboolean delete)
         cw->saved_picture = cw->picture;
         cw->picture = None;
     }
+    myDisplayErrorTrapPush (display_info);
 }
 
 static Picture
@@ -1630,53 +1634,45 @@ redraw_glx_texture (ScreenInfo *screen_info, XserverRegion region)
 #endif /* HAVE_EPOXY */
 
 #ifdef HAVE_PRESENT_EXTENSION
-static int
-present_error_handler (Display * dpy, XErrorEvent * err)
+static void
+present_error (DisplayInfo *display_info, int error_code)
 {
-    DisplayInfo *display_info;
-
-    display_info = myDisplayGetDefault ();
-    g_return_val_if_fail (display_info, 0);
+    GSList *screens;
+    g_warning ("Dismissing XPresent as unusable, error %i", error_code);
 
-    /* XPresentPixmap() can trigger a BadWindow rather than a BadMatch */
-    if (err->request_code == display_info->present_opcode &&
-        (err->error_code == BadWindow || err->error_code == BadMatch))
+    for (screens = display_info->screens; screens; screens = g_slist_next (screens))
     {
-        GSList *screens;
-
-        g_warning ("Dismissing XPresent as unusable, error %d for request %d",
-                    err->error_code, err->request_code);
-
-        for (screens = display_info->screens; screens; screens = g_slist_next (screens))
-        {
-            ScreenInfo *screen_info = ((ScreenInfo *) screens->data);
-
-            screen_info->present_pending = FALSE;
-            screen_info->use_present = FALSE;
-        }
-    }
+        ScreenInfo *screen_info = ((ScreenInfo *) screens->data);
 
-    /* Chain with our default error handler if available */
-    if (default_error_handler)
-    {
-        return (default_error_handler (dpy, err));
+        screen_info->present_pending = FALSE;
+        screen_info->use_present = FALSE;
     }
-    return 0;
 }
 
 static void
 present_flip (ScreenInfo *screen_info, XserverRegion region, Pixmap pixmap)
 {
     static guint32 present_serial;
+    DisplayInfo *display_info;
+    int result;
 
     g_return_if_fail (screen_info != NULL);
     g_return_if_fail (region != None);
     g_return_if_fail (pixmap != None);
     TRACE ("serial %d", present_serial);
 
-    XPresentPixmap (myScreenGetXDisplay (screen_info), screen_info->output,
+    display_info = screen_info->display_info;
+    myDisplayErrorTrapPush (display_info);
+    XPresentPixmap (display_info->dpy, screen_info->output,
                     pixmap, present_serial++, None, region, 0, 0, None, None, None,
                     PresentOptionNone, 0, 1, 0, NULL, 0);
+    result = myDisplayErrorTrapPop (display_info);
+
+    /* XPresentPixmap() can trigger a BadWindow rather than a BadMatch */
+    if ((result == BadWindow) || (result == BadMatch))
+    {
+        present_error (display_info, result);
+    }
 }
 #endif /* HAVE_PRESENT_EXTENSION */
 
@@ -1831,11 +1827,12 @@ get_window_picture (CWindow *cw)
     display_info = screen_info->display_info;
 
 #if HAVE_NAME_WINDOW_PIXMAP
+    myDisplayErrorTrapPush (display_info);
     if ((display_info->have_name_window_pixmap) && (cw->name_window_pixmap == None))
     {
         cw->name_window_pixmap = XCompositeNameWindowPixmap (display_info->dpy, cw->id);
     }
-    if (cw->name_window_pixmap != None)
+    if ((myDisplayErrorTrapPop (display_info) == Success) && (cw->name_window_pixmap != None))
     {
         draw = cw->name_window_pixmap;
     }
@@ -1843,8 +1840,15 @@ get_window_picture (CWindow *cw)
     format = get_window_format (cw);
     if (format)
     {
+        Picture pict;
+
+        myDisplayErrorTrapPush (display_info);
         pa.subwindow_mode = IncludeInferiors;
-        return XRenderCreatePicture (display_info->dpy, draw, format, CPSubwindowMode, &pa);
+        pict = XRenderCreatePicture (display_info->dpy, draw, format, CPSubwindowMode, &pa);
+        if (myDisplayErrorTrapPop (display_info) == Success)
+        {
+            return pict;
+        }
     }
 
     return None;
@@ -1864,11 +1868,14 @@ unredirect_win (CWindow *cw)
         screen_info = cw->screen_info;
         display_info = screen_info->display_info;
 
+        myDisplayErrorTrapPush (display_info);
+        XCompositeUnredirectWindow (display_info->dpy, cw->id, display_info->composite_mode);
+        myDisplayErrorTrapPopIgnored (display_info);
+
         free_win_data (cw, FALSE);
         cw->redirected = FALSE;
-
-        XCompositeUnredirectWindow (display_info->dpy, cw->id, display_info->composite_mode);
-        TRACE ("window 0x%lx unredirected, wins_unredirected is %i", cw->id, screen_info->wins_unredirected);
+        TRACE ("window 0x%lx unredirected, wins_unredirected is %i",
+               cw->id, screen_info->wins_unredirected);
     }
 }
 
@@ -2077,6 +2084,8 @@ paint_all (ScreenInfo *screen_info, XserverRegion region, gushort buffer)
     screen_width = screen_info->width;
     screen_height = screen_info->height;
 
+    myDisplayErrorTrapPush (display_info);
+
     /* Create root buffer if not done yet */
     if (screen_info->rootPixmap[buffer] == None)
     {
@@ -2315,6 +2324,8 @@ paint_all (ScreenInfo *screen_info, XserverRegion region, gushort buffer)
     }
 
     XFixesDestroyRegion (dpy, paint_region);
+
+    myDisplayErrorTrapPopIgnored (display_info);
 }
 
 static void
@@ -2532,6 +2543,7 @@ repair_win (CWindow *cw, XRectangle *r)
         return;
     }
 
+    myDisplayErrorTrapPush (display_info);
     if (cw->damaged)
     {
         parts = XFixesCreateRegion (display_info->dpy, NULL, 0);
@@ -2547,6 +2559,7 @@ repair_win (CWindow *cw, XRectangle *r)
         /* Subtract all damage from the window's damage */
         XDamageSubtract (display_info->dpy, cw->damage, None, None);
     }
+    myDisplayErrorTrapPopIgnored (display_info);
 
     if (parts)
     {
@@ -2921,7 +2934,12 @@ add_win (DisplayInfo *display_info, Window id, Client *c)
 
     if (new->attr.class != InputOnly)
     {
+        myDisplayErrorTrapPush (screen_info->display_info);
         new->damage = XDamageCreate (display_info->dpy, id, XDamageReportNonEmpty);
+        if (myDisplayErrorTrapPop (screen_info->display_info) != Success)
+        {
+            new->damage = None;
+        }
     }
     else
     {
@@ -4272,7 +4290,6 @@ compositorInitDisplay (DisplayInfo *display_info)
     else
     {
         display_info->have_present = TRUE;
-        default_error_handler = XSetErrorHandler (present_error_handler);
         DBG ("present opcode:  %i", display_info->present_opcode);
         DBG ("present event base: %i", display_info->present_event_base);
         DBG ("present error base: %i", display_info->present_error_base);
diff --git a/src/events.c b/src/events.c
index b4acdd6..9b78bd0 100644
--- a/src/events.c
+++ b/src/events.c
@@ -1383,7 +1383,9 @@ handleConfigureRequest (DisplayInfo *display_info, XConfigureRequestEvent * ev)
     else
     {
         TRACE ("unmanaged configure request for window 0x%lx", ev->window);
+        myDisplayErrorTrapPush (display_info);
         XConfigureWindow (display_info->dpy, ev->window, ev->value_mask, &wc);
+        myDisplayErrorTrapPopIgnored (display_info);
     }
 
     return EVENT_FILTER_REMOVE;
diff --git a/src/focus.c b/src/focus.c
index 1549fdc..3760cf7 100644
--- a/src/focus.c
+++ b/src/focus.c
@@ -582,6 +582,7 @@ clientSetFocus (ScreenInfo *screen_info, Client *c, guint32 timestamp, unsigned
              * When shaded, the client window is unmapped, so it can not be focused.
              * Instead, we focus the frame that is still mapped.
              */
+            myDisplayErrorTrapPush (screen_info->display_info);
             if (FLAG_TEST (c->flags, CLIENT_FLAG_SHADED))
             {
                 XSetInputFocus (myScreenGetXDisplay (screen_info), c->frame, RevertToPointerRoot, timestamp);
@@ -590,6 +591,12 @@ clientSetFocus (ScreenInfo *screen_info, Client *c, guint32 timestamp, unsigned
             {
                 XSetInputFocus (myScreenGetXDisplay (screen_info), c->window, RevertToPointerRoot, timestamp);
             }
+            if (myDisplayErrorTrapPop (screen_info->display_info) != Success)
+            {
+                client_focus = NULL;
+                clientFocusNone (screen_info, c2, timestamp);
+                clientClearDelayedFocus ();
+            }
         }
         else if (flags & FOCUS_TRANSITION)
         {
@@ -606,7 +613,7 @@ clientSetFocus (ScreenInfo *screen_info, Client *c, guint32 timestamp, unsigned
         if (FLAG_TEST(c->wm_flags, WM_FLAG_TAKEFOCUS))
         {
             pending_focus = c;
-            sendClientMessage (c->screen_info, c->window, WM_TAKE_FOCUS, timestamp);
+            sendClientMessage (screen_info, c->window, WM_TAKE_FOCUS, timestamp);
         }
     }
     else
diff --git a/src/hints.c b/src/hints.c
index 69a1558..33ee033 100644
--- a/src/hints.c
+++ b/src/hints.c
@@ -83,22 +83,29 @@ getWMState (DisplayInfo *display_info, Window w)
     unsigned long items_read, items_left;
     unsigned char *data;
     unsigned long state;
+    int result, status;
 
     TRACE ("window 0x%lx", w);
 
     data = NULL;
     state = WithdrawnState;
-    if ((XGetWindowProperty (display_info->dpy, w, display_info->atoms[WM_STATE],
-                             0, 3L, FALSE, display_info->atoms[WM_STATE],
-                             &real_type, &real_format, &items_read, &items_left,
-                             (unsigned char **) &data) == Success) && (items_read))
+
+    myDisplayErrorTrapPush (display_info);
+    status = XGetWindowProperty (display_info->dpy, w, display_info->atoms[WM_STATE],
+                                 0, 3L, FALSE, display_info->atoms[WM_STATE],
+                                 &real_type, &real_format, &items_read, &items_left,
+                                 (unsigned char **) &data);
+    result = myDisplayErrorTrapPop (display_info);
+
+    if ((result == Success) &&
+        (status == Success) &&
+        (items_read) &&
+        (data != NULL))
     {
         state = *data;
-        if (data)
-        {
-            XFree (data);
-        }
     }
+    XFree (data);
+
     return state;
 }
 
@@ -111,10 +118,11 @@ setWMState (DisplayInfo *display_info, Window w, unsigned long state)
 
     data[0] = state;
     data[1] = None;
-
+    myDisplayErrorTrapPush (display_info);
     XChangeProperty (display_info->dpy, w, display_info->atoms[WM_STATE],
                      display_info->atoms[WM_STATE], 32, PropModeReplace,
                      (unsigned char *) data, 2);
+    myDisplayErrorTrapPopIgnored (display_info);
 }
 
 PropMwmHints *
@@ -124,27 +132,33 @@ getMotifHints (DisplayInfo *display_info, Window w)
     int real_format;
     unsigned long items_read, items_left;
     unsigned char *data;
-    PropMwmHints *result;
+    PropMwmHints *hints;
+    int result, status;
 
     TRACE ("window 0x%lx", w);
 
     data = NULL;
-    result = NULL;
-    if ((XGetWindowProperty (display_info->dpy, w, display_info->atoms[MOTIF_WM_HINTS], 0L, MWM_HINTS_ELEMENTS,
-                FALSE, display_info->atoms[MOTIF_WM_HINTS], &real_type, &real_format, &items_read,
-                &items_left, (unsigned char **) &data) == Success))
+    hints = NULL;
+
+    myDisplayErrorTrapPush (display_info);
+    status = XGetWindowProperty (display_info->dpy, w, display_info->atoms[MOTIF_WM_HINTS], 0L,
+                                 MWM_HINTS_ELEMENTS, FALSE, display_info->atoms[MOTIF_WM_HINTS],
+                                 &real_type, &real_format, &items_read, &items_left,
+                                 (unsigned char **) &data);
+    result = myDisplayErrorTrapPop (display_info);
+
+    if ((status == Success) &&
+        (result == Success) &&
+        (data != NULL) &&
+        (items_read >= MWM_HINTS_ELEMENTS))
     {
-        if (items_read >= MWM_HINTS_ELEMENTS)
-        {
-            result = g_new0(PropMwmHints, 1);
-            memcpy (result, data, sizeof (PropMwmHints));
-        }
-        if (data)
-        {
-            XFree (data);
-        }
+        hints = g_new0 (PropMwmHints, 1);
+        memcpy (hints, data, sizeof (PropMwmHints));
     }
-    return result;
+
+    XFree (data);
+
+    return hints;
 }
 
 unsigned int
@@ -154,72 +168,80 @@ getWMProtocols (DisplayInfo *display_info, Window w)
     gint i, n;
     Atom atype;
     int aformat;
-    unsigned int result;
+    unsigned int flags;
     unsigned long bytes_remain, nitems;
     unsigned char *data;
+    int result, status;
 
     TRACE ("window 0x%lx", w);
 
-    result = 0;
-    if (XGetWMProtocols (display_info->dpy, w, &protocols, &n))
+    flags = 0;
+    protocols = NULL;
+    myDisplayErrorTrapPush (display_info);
+    status = XGetWMProtocols (display_info->dpy, w, &protocols, &n);
+    result = myDisplayErrorTrapPop (display_info);
+
+    if ((status == Success) && (result == Success) && (protocols != NULL))
     {
         for (i = 0, ap = protocols; i < n; i++, ap++)
         {
             if (*ap == display_info->atoms[WM_TAKE_FOCUS])
             {
-                result |= WM_PROTOCOLS_TAKE_FOCUS;
+                flags |= WM_PROTOCOLS_TAKE_FOCUS;
             }
             if (*ap == display_info->atoms[WM_DELETE_WINDOW])
             {
-                result |= WM_PROTOCOLS_DELETE_WINDOW;
+                flags |= WM_PROTOCOLS_DELETE_WINDOW;
             }
             /* KDE extension */
             if (*ap == display_info->atoms[NET_WM_CONTEXT_HELP])
             {
-                result |= WM_PROTOCOLS_CONTEXT_HELP;
+                flags |= WM_PROTOCOLS_CONTEXT_HELP;
             }
             /* Ping */
             if (*ap == display_info->atoms[NET_WM_PING])
             {
-                result |= WM_PROTOCOLS_PING;
+                flags |= WM_PROTOCOLS_PING;
             }
         }
-        if (protocols)
-        {
-            XFree (protocols);
-        }
     }
     else
     {
-        if ((XGetWindowProperty (display_info->dpy, w,
-                    display_info->atoms[WM_PROTOCOLS], 0L, 10L, FALSE,
-                    display_info->atoms[WM_PROTOCOLS], &atype,
-                    &aformat, &nitems, &bytes_remain,
-                    (unsigned char **) &data)) == Success)
+        myDisplayErrorTrapPush (display_info);
+        status = XGetWindowProperty (display_info->dpy, w,
+                                     display_info->atoms[WM_PROTOCOLS],
+                                     0L, 10L, FALSE,
+                                     display_info->atoms[WM_PROTOCOLS],
+                                     &atype, &aformat, &nitems, &bytes_remain,
+                                     (unsigned char **) &data);
+        result = myDisplayErrorTrapPop (display_info);
+
+        if ((status == Success) &&
+            (result == Success) &&
+            (data != NULL))
         {
             for (i = 0, ap = (Atom *) data; (unsigned long) i < nitems; i++, ap++)
             {
                 if (*ap == display_info->atoms[WM_TAKE_FOCUS])
                 {
-                    result |= WM_PROTOCOLS_TAKE_FOCUS;
+                    flags |= WM_PROTOCOLS_TAKE_FOCUS;
                 }
                 if (*ap == display_info->atoms[WM_DELETE_WINDOW])
                 {
-                    result |= WM_PROTOCOLS_DELETE_WINDOW;
+                    flags |= WM_PROTOCOLS_DELETE_WINDOW;
                 }
                 /* KDE extension */
                 if (*ap == display_info->atoms[NET_WM_CONTEXT_HELP])
                 {
-                    result |= WM_PROTOCOLS_CONTEXT_HELP;
+                    flags |= WM_PROTOCOLS_CONTEXT_HELP;
                 }
             }
-            if (data)
-            {
-                XFree (data);
-            }
         }
+        XFree (data);
     }
-    return result;
+    XFree (protocols);
+
+    return flags;
 }
 
 gboolean
@@ -230,6 +252,7 @@ getHint (DisplayInfo *display_info, Window w, int atom_id, long *value)
     unsigned char *data;
     int real_format;
     gboolean success;
+    int result, status;
 
     g_return_val_if_fail (((atom_id >= 0) && (atom_id < ATOM_COUNT)), FALSE);
     TRACE ("window 0x%lx atom %i", w, atom_id);
@@ -238,17 +261,22 @@ getHint (DisplayInfo *display_info, Window w, int atom_id, long *value)
     *value = 0;
     data = NULL;
 
-    if ((XGetWindowProperty (display_info->dpy, w, display_info->atoms[atom_id], 0L, 1L,
-                             FALSE, XA_CARDINAL, &real_type, &real_format, &items_read, &items_left,
-                             (unsigned char **) &data) == Success) && (items_read))
+    myDisplayErrorTrapPush (display_info);
+    status = XGetWindowProperty (display_info->dpy, w, display_info->atoms[atom_id],
+                                 0L, 1L, FALSE, XA_CARDINAL, &real_type, &real_format,
+                                 &items_read, &items_left, (unsigned char **) &data);
+    result = myDisplayErrorTrapPop (display_info);
+
+    if ((result == Success) &&
+        (status == Success) &&
+        (data != NULL) &&
+        (items_read > 0))
     {
         *value = *((long *) data) & ((1LL << real_format) - 1);
-        if (data)
-        {
-            XFree (data);
-        }
+        XFree (data);
         success = TRUE;
     }
+
     return success;
 }
 
@@ -258,8 +286,10 @@ setHint (DisplayInfo *display_info, Window w, int atom_id, long value)
     g_return_if_fail ((atom_id >= 0) && (atom_id < ATOM_COUNT));
     TRACE ("window 0x%lx atom %i", w, atom_id);
 
+    myDisplayErrorTrapPush (display_info);
     XChangeProperty (display_info->dpy, w, display_info->atoms[atom_id], XA_CARDINAL,
                      32, PropModeReplace, (unsigned char *) &value, 1);
+    myDisplayErrorTrapPopIgnored (display_info);
 }
 
 void
@@ -272,15 +302,24 @@ getDesktopLayout (DisplayInfo *display_info, Window root, int ws_count, NetWmDes
     unsigned char *data;
     int real_format;
     gboolean success;
+    int result, status;
 
     ptr = NULL;
     data = NULL;
     success = FALSE;
 
-    if ((XGetWindowProperty (display_info->dpy, root, display_info->atoms[NET_DESKTOP_LAYOUT],
-                0L, 4L, FALSE, XA_CARDINAL,
-                &real_type, &real_format, &items_read, &items_left,
-                (unsigned char **) &data) == Success) && (items_read >= 3))
+    myDisplayErrorTrapPush (display_info);
+    status = XGetWindowProperty (display_info->dpy, root,
+                                 display_info->atoms[NET_DESKTOP_LAYOUT],
+                                 0L, 4L, FALSE, XA_CARDINAL,
+                                 &real_type, &real_format, &items_read, &items_left,
+                                 (unsigned char **) &data);
+    result = myDisplayErrorTrapPop (display_info);
+
+    if ((result == Success) &&
+        (status == Success) &&
+        (data != NULL) &&
+        (items_read >= 3))
     {
         do
         {
@@ -321,9 +360,8 @@ getDesktopLayout (DisplayInfo *display_info, Window root, int ws_count, NetWmDes
             layout->start = start;
             success = TRUE;
         } while (0);
-
-        XFree (data);
     }
+    XFree (data);
 
     if (!success)
     {
@@ -445,6 +483,7 @@ getAtomList (DisplayInfo *display_info, Window w, int atom_id, Atom ** atoms_p,
     unsigned long bytes_after;
     unsigned char *data;
     Atom *atoms;
+    int result, status;
 
     *atoms_p = NULL;
     *n_atoms_p = 0;
@@ -452,19 +491,25 @@ getAtomList (DisplayInfo *display_info, Window w, int atom_id, Atom ** atoms_p,
     g_return_val_if_fail (((atom_id >= 0) && (atom_id < ATOM_COUNT)), FALSE);
     TRACE ("window 0x%lx atom %i", w, atom_id);
 
-    if ((XGetWindowProperty (display_info->dpy, w, display_info->atoms[atom_id],
-                             0, G_MAXLONG, FALSE, XA_ATOM, &type, &format, &n_atoms,
-                             &bytes_after, (unsigned char **) &data) != Success) || (type == None))
+    myDisplayErrorTrapPush (display_info);
+    status = XGetWindowProperty (display_info->dpy, w, display_info->atoms[atom_id],
+                                 0, G_MAXLONG, FALSE, XA_ATOM, &type, &format, &n_atoms,
+                                 &bytes_after, (unsigned char **) &data);
+    result = myDisplayErrorTrapPop (display_info);
+
+    if ((result != Success) ||
+        (status != Success) ||
+        (data == NULL) ||
+        (type == None))
     {
+        XFree (data);
         return FALSE;
     }
+
     atoms = (Atom *) data;
     if (!check_type_and_format (32, XA_ATOM, -1, format, type))
     {
-        if (atoms)
-        {
-            XFree (atoms);
-        }
+        XFree (atoms);
         *atoms_p = NULL;
         *n_atoms_p = 0;
         return FALSE;
@@ -486,6 +531,7 @@ getCardinalList (DisplayInfo *display_info, Window w, int atom_id, unsigned long
     unsigned long bytes_after;
     unsigned char *data;
     unsigned long *cardinals;
+    int result, status;
 
     *cardinals_p = NULL;
     *n_cardinals_p = 0;
@@ -493,13 +539,22 @@ getCardinalList (DisplayInfo *display_info, Window w, int atom_id, unsigned long
     g_return_val_if_fail (((atom_id >= 0) && (atom_id < ATOM_COUNT)), FALSE);
     TRACE ("window 0x%lx atom %i", w, atom_id);
 
-    if ((XGetWindowProperty (display_info->dpy, w, display_info->atoms[atom_id],
-                             0, G_MAXLONG, FALSE, XA_CARDINAL,
-                             &type, &format, &n_cardinals, &bytes_after,
-                             (unsigned char **) &data) != Success) || (type == None))
+    myDisplayErrorTrapPush (display_info);
+    status = XGetWindowProperty (display_info->dpy, w, display_info->atoms[atom_id],
+                                 0, G_MAXLONG, FALSE, XA_CARDINAL,
+                                 &type, &format, &n_cardinals, &bytes_after,
+                                 (unsigned char **) &data);
+    result = myDisplayErrorTrapPop (display_info);
+
+    if ((result != Success) ||
+        (status != Success) ||
+        (data == NULL) ||
+        (type == None))
     {
+        XFree (data);
         return FALSE;
     }
+
     cardinals = (unsigned long *) data;
     if (!check_type_and_format (32, XA_CARDINAL, -1, format, type))
     {
@@ -535,6 +590,7 @@ setNetWorkarea (DisplayInfo *display_info, Window root, int nb_workspaces, int w
         *ptr++ = (unsigned long) (width  - (m[STRUTS_LEFT] + m[STRUTS_RIGHT]));
         *ptr++ = (unsigned long) (height - (m[STRUTS_TOP]  + m[STRUTS_BOTTOM]));
     }
+
     XChangeProperty (display_info->dpy, root, display_info->atoms[NET_WORKAREA],
                      XA_CARDINAL, 32, PropModeReplace, (unsigned char *) data, j * 4);
     g_free (data);
@@ -551,8 +607,10 @@ setNetFrameExtents (DisplayInfo *display_info, Window w, int top, int left, int
     data[1] = (unsigned long) right;
     data[2] = (unsigned long) top;
     data[3] = (unsigned long) bottom;
+    myDisplayErrorTrapPush (display_info);
     XChangeProperty (display_info->dpy, w, display_info->atoms[NET_FRAME_EXTENTS],
                      XA_CARDINAL, 32, PropModeReplace, (unsigned char *) data, 4);
+    myDisplayErrorTrapPopIgnored (display_info);
 }
 
 void
@@ -566,8 +624,10 @@ setNetFullscreenMonitors (DisplayInfo *display_info, Window w, gint top, gint bo
     data[1] = (unsigned long) bottom;
     data[2] = (unsigned long) left;
     data[3] = (unsigned long) right;
+    myDisplayErrorTrapPush (display_info);
     XChangeProperty (display_info->dpy, w, display_info->atoms[NET_WM_FULLSCREEN_MONITORS],
                      XA_CARDINAL, 32, PropModeReplace, (unsigned char *) data, 4);
+    myDisplayErrorTrapPopIgnored (display_info);
 }
 
 int
@@ -615,10 +675,11 @@ setUTF8StringHint (DisplayInfo *display_info, Window w, int atom_id, const gchar
     g_return_if_fail ((atom_id >= 0) && (atom_id < ATOM_COUNT));
 
     TRACE ("window 0x%lx atom %i", w, atom_id);
-
+    myDisplayErrorTrapPush (display_info);
     XChangeProperty (display_info->dpy, w, display_info->atoms[atom_id],
                      display_info->atoms[UTF8_STRING], 8, PropModeReplace,
                      (unsigned char *) val, strlen (val));
+    myDisplayErrorTrapPopIgnored (display_info);
 }
 
 void
@@ -708,26 +769,35 @@ getUTF8StringData (DisplayInfo *display_info, Window w, int atom_id, gchar **str
     unsigned long bytes_after;
     unsigned char *str;
     unsigned long n_items;
+    int result, status;
 
     g_return_val_if_fail (((atom_id >= 0) && (atom_id < ATOM_COUNT)), FALSE);
     TRACE ("window 0x%lx atom %i", w, atom_id);
 
     *str_p = NULL;
-    if ((XGetWindowProperty (display_info->dpy, w, display_info->atoms[atom_id],
-                             0, G_MAXLONG, FALSE, display_info->atoms[UTF8_STRING], &type,
-                             &format, &n_items, &bytes_after, (unsigned char **) &str) != Success) || (type == None))
+    str = NULL;
+
+    myDisplayErrorTrapPush (display_info);
+    status = XGetWindowProperty (display_info->dpy, w, display_info->atoms[atom_id],
+                                 0, G_MAXLONG, FALSE, display_info->atoms[UTF8_STRING],
+                                 &type, &format, &n_items, &bytes_after,
+                                 (unsigned char **) &str);
+    result = myDisplayErrorTrapPop (display_info);
+
+    if ((result != Success) ||
+        (status != Success) ||
+        (str == NULL) ||
+        (type == None))
     {
         TRACE ("no UTF8_STRING property found");
+        XFree (str);
         return FALSE;
     }
 
     if (!check_type_and_format (8, display_info->atoms[UTF8_STRING], -1, format, type))
     {
         TRACE ("UTF8_STRING value invalid");
-        if (str)
-        {
-            XFree (str);
-        }
+        XFree (str);
         return FALSE;
     }
 
@@ -838,15 +908,22 @@ getWindowProp (DisplayInfo *display_info, Window window, int atom_id, Window *w)
     unsigned long nitems;
     unsigned long bytes_after;
     unsigned char *prop;
+    int result, status;
 
     g_return_val_if_fail (window != None, FALSE);
     g_return_val_if_fail (((atom_id >= 0) && (atom_id < ATOM_COUNT)), FALSE);
     TRACE ("window 0x%lx atom id %i", window, atom_id);
 
     *w = None;
-    if (XGetWindowProperty (display_info->dpy, window, display_info->atoms[atom_id],
-                            0L, 1L, FALSE, XA_WINDOW, &type, &format, &nitems,
-                            &bytes_after, (unsigned char **) &prop) == Success)
+    prop = NULL;
+
+    myDisplayErrorTrapPush (display_info);
+    status = XGetWindowProperty (display_info->dpy, window, display_info->atoms[atom_id],
+                                 0L, 1L, FALSE, XA_WINDOW, &type, &format, &nitems,
+                                 &bytes_after, (unsigned char **) &prop);
+    result = myDisplayErrorTrapPop (display_info);
+
+    if ((status == Success) && (result == Success))
     {
         if (prop)
         {
@@ -860,7 +937,7 @@ getWindowProp (DisplayInfo *display_info, Window window, int atom_id, Window *w)
         }
     }
 
-    return TRUE;
+    return (result == Success);
 }
 
 gboolean
@@ -968,22 +1045,32 @@ getNetWMUserTime (DisplayInfo *display_info, Window window, guint32 *timestamp)
     unsigned long nitems;
     unsigned long bytes_after;
     unsigned char *data = NULL;
+    int result, status;
 
     g_return_val_if_fail (window != None, FALSE);
     TRACE ("window 0x%lx", window);
 
-    if (XGetWindowProperty (display_info->dpy, window, display_info->atoms[NET_WM_USER_TIME],
-                            0L, 1L, FALSE, XA_CARDINAL, &actual_type, &actual_format, &nitems,
-                            &bytes_after, (unsigned char **) &data) == Success)
+    myDisplayErrorTrapPush (display_info);
+    status = XGetWindowProperty (display_info->dpy, window,
+                                 display_info->atoms[NET_WM_USER_TIME],
+                                 0L, 1L, FALSE, XA_CARDINAL, &actual_type,
+                                 &actual_format, &nitems, &bytes_after,
+                                 (unsigned char **) &data);
+    result = myDisplayErrorTrapPop (display_info);
+
+    if ((status == Success) &&
+        (result == Success) &&
+        (data != NULL) &&
+        (actual_type == XA_CARDINAL) &&
+        (nitems == 1) &&
+        (bytes_after == 0))
     {
-        if ((data) && (actual_type == XA_CARDINAL)
-            && (nitems == 1) && (bytes_after == 0))
-        {
-            *timestamp= *((guint32 *) data);
-            XFree (data);
-            return TRUE;
-        }
+        *timestamp = *((guint32 *) data);
+        XFree (data);
+        return TRUE;
     }
+
+    XFree (data);
     *timestamp = (guint32) CurrentTime;
 
     return FALSE;
@@ -1064,29 +1151,34 @@ getKDEIcon (DisplayInfo *display_info, Window window, Pixmap * pixmap, Pixmap *
     unsigned long bytes_after;
     unsigned char *data;
     Pixmap *icons;
+    int result, status;
 
     TRACE ("window 0x%lx", window);
 
     *pixmap = None;
     *mask = None;
-
     icons = NULL;
-    if (XGetWindowProperty (display_info->dpy, window, display_info->atoms[KWM_WIN_ICON],
-                            0L, G_MAXLONG, FALSE, display_info->atoms[KWM_WIN_ICON], &type,
-                            &format, &nitems, &bytes_after, (unsigned char **)&data) != Success)
-    {
-        return FALSE;
-    }
-    icons = (Pixmap *) data;
-    if (type != display_info->atoms[KWM_WIN_ICON])
+    data = NULL;
+
+    myDisplayErrorTrapPush (display_info);
+    status = XGetWindowProperty (display_info->dpy, window,
+                                 display_info->atoms[KWM_WIN_ICON],
+                                 0L, G_MAXLONG, FALSE,
+                                 display_info->atoms[KWM_WIN_ICON],
+                                 &type, &format, &nitems, &bytes_after,
+                                 (unsigned char **) &data);
+    result = myDisplayErrorTrapPop (display_info);
+
+    if ((status != Success) ||
+        (result != Success) ||
+        (data == NULL) ||
+        (type != display_info->atoms[KWM_WIN_ICON]))
     {
-        if (icons)
-        {
-            XFree (icons);
-        }
+        XFree (data);
         return FALSE;
     }
 
+    icons = (Pixmap *) data;
     *pixmap = icons[0];
     *mask = icons[1];
 
@@ -1101,28 +1193,31 @@ getRGBIconData (DisplayInfo *display_info, Window window, unsigned long **data,
     Atom type;
     int format;
     unsigned long bytes_after;
+    int result, status;
 
     TRACE ("window 0x%lx", window);
 
-    if (XGetWindowProperty (display_info->dpy, window, display_info->atoms[NET_WM_ICON],
-                            0L, G_MAXLONG, FALSE, XA_CARDINAL, &type, &format, nitems,
-                            &bytes_after, (unsigned char **) data) != Success)
-    {
-        *data = NULL;
-        return FALSE;
-    }
+    *data = NULL;
+    type = None;
 
-    if (type != XA_CARDINAL)
+    myDisplayErrorTrapPush (display_info);
+    status = XGetWindowProperty (display_info->dpy, window,
+                                 display_info->atoms[NET_WM_ICON],
+                                 0L, G_MAXLONG, FALSE, XA_CARDINAL,
+                                 &type, &format, nitems, &bytes_after,
+                                 (unsigned char **) data);
+    result = myDisplayErrorTrapPop (display_info);
+
+    if ((status != Success) ||
+        (result != Success) ||
+        (type != XA_CARDINAL))
     {
-        if (*data)
-        {
-            XFree (*data);
-        }
+        XFree (*data);
         *data = NULL;
         return FALSE;
     }
 
-    return TRUE;
+    return (data != NULL);
 }
 
 gboolean
@@ -1272,24 +1367,35 @@ checkKdeSystrayWindow (DisplayInfo *display_info, Window window)
     unsigned long bytes_after;
     unsigned char *data;
     Window trayIconForWindow;
+    int result, status;
 
     g_return_val_if_fail (window != None, FALSE);
     TRACE ("window 0x%lx", window);
 
-    XGetWindowProperty(display_info->dpy, window, display_info->atoms[KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR],
-                       0L, sizeof(Window), FALSE, XA_WINDOW, &actual_type, &actual_format,
-                       &nitems, &bytes_after, (unsigned char **) &data);
-
     trayIconForWindow = None;
+    data = NULL;
+
+    myDisplayErrorTrapPush (display_info);
+    status = XGetWindowProperty (display_info->dpy, window,
+                                 display_info->atoms[KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR],
+                                 0L, sizeof(Window), FALSE, XA_WINDOW, &actual_type,
+                                 &actual_format, &nitems, &bytes_after,
+                                 (unsigned char **) &data);
+    result = myDisplayErrorTrapPop (display_info);
+
+    if ((status != Success) || (result != Success))
+    {
+        XFree (data);
+        return FALSE;
+    }
+
     if (data)
     {
         trayIconForWindow = *((Window *) data);
         XFree (data);
     }
 
-    if ((actual_format == None) ||
-        (actual_type != XA_WINDOW) ||
-        (trayIconForWindow == None))
+    if ((actual_format == None) || (actual_type != XA_WINDOW) || (trayIconForWindow == None))
     {
         return FALSE;
     }
diff --git a/src/netwm.c b/src/netwm.c
index a04fe5b..3c0121f 100644
--- a/src/netwm.c
+++ b/src/netwm.c
@@ -134,9 +134,12 @@ clientSetNetState (Client * c)
         TRACE ("focused");
         data[i++] = display_info->atoms[NET_WM_STATE_FOCUSED];
     }
+
+    myDisplayErrorTrapPush (display_info);
     XChangeProperty (display_info->dpy, c->window,
                      display_info->atoms[NET_WM_STATE], XA_ATOM, 32,
                      PropModeReplace, (unsigned char *) data, i);
+    myDisplayErrorTrapPopIgnored (display_info);
 }
 
 void
@@ -979,8 +982,9 @@ clientSetNetClientList (ScreenInfo * screen_info, Atom a, GList * list)
             Client *c = (Client *) index_src->data;
             *index_dest = c->window;
         }
-        XChangeProperty (myScreenGetXDisplay (screen_info), screen_info->xroot, a, XA_WINDOW, 32, PropModeReplace,
-            (unsigned char *) listw, size);
+        XChangeProperty (myScreenGetXDisplay (screen_info),
+                         screen_info->xroot, a, XA_WINDOW, 32,
+                         PropModeReplace, (unsigned char *) listw, size);
         g_free (listw);
     }
 }
@@ -1202,8 +1206,11 @@ clientSetNetActions (Client * c)
         atoms[i++] = display_info->atoms[NET_WM_ACTION_CHANGE_DESKTOP];
         atoms[i++] = display_info->atoms[NET_WM_ACTION_STICK];
     }
+
+    myDisplayErrorTrapPush (display_info);
     XChangeProperty (clientGetXDisplay (c), c->window, display_info->atoms[NET_WM_ALLOWED_ACTIONS],
                      XA_ATOM, 32, PropModeReplace, (unsigned char *) atoms, i);
+    myDisplayErrorTrapPopIgnored (display_info);
 }
 
 void
@@ -1407,7 +1414,8 @@ clientSetNetActiveWindow (ScreenInfo *screen_info, Client *c, guint32 timestamp)
     {
         data[0] = (unsigned long) c->window;
     }
-    XChangeProperty (myScreenGetXDisplay (screen_info), screen_info->xroot, display_info->atoms[NET_ACTIVE_WINDOW], XA_WINDOW, 32,
+    XChangeProperty (myScreenGetXDisplay (screen_info), screen_info->xroot,
+                     display_info->atoms[NET_ACTIVE_WINDOW], XA_WINDOW, 32,
                      PropModeReplace, (unsigned char *) data, 2);
 }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list