From: Rodolfo García Peñas (kix) Date: Thu, 22 Nov 2012 21:40:12 +0000 (+0100) Subject: Avoid crash on icon move without command X-Git-Tag: wmaker-0.95.4~12 X-Git-Url: https://repo.or.cz/w/wmaker-crm.git/commitdiff_plain/bf2f9421388a56f804b7912de137fb12d062f106 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. --- 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 {