From: "Rodolfo García Peñas (kix)" <[email protected]>

This patch avoid a crash when moving an icon without command.
To reproduce the problem:

1. Launch an application, for example xeyes, with appicon.
2. Move the appicon to the clip.
3. Close the application.
4. Edit the appicon in the clip, and empty the commands fields.
5. Move the appicon from the clip to the dock. -> Crash.

The crash happends because the appicon don't have command AND
the application is not running, therefore "wwin" is NULL.

This patch test if the application is running (the icon has wwin),
before get the command from the application.
---
 src/dock.c |   24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/dock.c b/src/dock.c
index 6e2e0e3..f503e14 100644
--- a/src/dock.c
+++ b/src/dock.c
@@ -1855,18 +1855,21 @@ Bool wDockAttachIcon(WDock *dock, WAppIcon *icon, int 
x, int y, Bool update_icon
 {
        WWindow *wwin;
        Bool lupdate_icon = False;
+       char *command = NULL;
        int index;
 
-       wwin = icon->icon->owner;
        icon->editing = 0;
 
        if (update_icon)
                lupdate_icon = True;
 
        if (icon->command == NULL) {
-               char *command;
+               /* Try to get the command for the window, if it is running! */
+               if (icon->icon->owner) {
+                       wwin = icon->icon->owner;
+                       command = GetCommandForWindow(wwin->client_win);
+               }
 
-               command = GetCommandForWindow(wwin->client_win);
                if (command) {
                        icon->command = command;
                } else {
@@ -1986,18 +1989,18 @@ static void reattachIcon(WDock *dock, WAppIcon *icon, 
int x, int y)
 static Bool moveIconBetweenDocks(WDock *src, WDock *dest, WAppIcon *icon, int 
x, int y)
 {
        WWindow *wwin;
-       char *command;
+       char *command = NULL;
        int index;
        Bool update_icon = False;
 
+       /* Check if no move needed, we're already there */
        if (src == dest)
-               return True;    /* No move needed, we're already there */
+               return True;
 
+       /* Check if destination exists */
        if (dest == NULL)
                return False;
 
-       wwin = icon->icon->owner;
-
        /*
         * For the moment we can't do this if we move icons in Clip from one
         * workspace to other, because if we move two or more icons without
@@ -2005,7 +2008,12 @@ static Bool moveIconBetweenDocks(WDock *src, WDock 
*dest, WAppIcon *icon, int x,
         * moved icons it applies. -Dan
         */
        if ((dest->type == WM_DOCK /*|| dest->keep_attracted */ ) && 
icon->command == NULL) {
-               command = GetCommandForWindow(wwin->client_win);
+               /* Try to get the command for the window, if it is running! */
+               if (icon->icon->owner) {
+                       wwin = icon->icon->owner;
+                       command = GetCommandForWindow(wwin->client_win);
+               }
+
                if (command) {
                        icon->command = command;
                } else {
-- 
1.7.10.4


-- 
To unsubscribe, send mail to [email protected].

Reply via email to