From bf2f9421388a56f804b7912de137fb12d062f106 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20=28kix=29?= Date: Thu, 22 Nov 2012 22:40:12 +0100 Subject: [PATCH] Avoid crash on icon move without command 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 icon->icon->owner is NULL and then wwin will be NULL. Then the call of wwin->client_win will crash. This patch checks if icon->icon->owner is not null (application is running) and then assign it to wwin. Then get the command from the running application. --- src/dock.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/dock.c b/src/dock.c index 6e2e0e31..21d6aeec 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; + /* If icon->owner exists, it means the application 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,7 +1989,7 @@ 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; @@ -1996,8 +1999,6 @@ static Bool moveIconBetweenDocks(WDock *src, WDock *dest, WAppIcon *icon, int x, 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 +2006,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); + /* If icon->owner exists, it means the application is running */ + if (icon->icon->owner) { + wwin = icon->icon->owner; + command = GetCommandForWindow(wwin->client_win); + } + if (command) { icon->command = command; } else { -- 2.11.4.GIT