add: if (dock->screen_ptr->last_dock == dock) dock->screen_ptr->last_dock = NULL;
context: wDockDestroy(WDock *dock){    int i;    WAppIcon *aicon;    for (i=(dock->type == WM_CLIP) ? 1 : 0; i<dock->max_icons; i++) {        aicon = dock->icon_array[i];        if (aicon) {            int keepit = aicon->running && wApplicationOf(aicon->main_window);            wDockDetach(dock, aicon);            if (keepit) {                PlaceIcon(dock->screen_ptr, &aicon->x_pos, &aicon->y_pos);                XMoveWindow(dpy, aicon->icon->core->window,                            aicon->x_pos, aicon->y_pos);                if (!dock->mapped || dock->collapsed)                    XMapWindow(dpy, aicon->icon->core->window);            }        }    }    if (wPreferences.auto_arrange_icons)        wArrangeIcons(dock->screen_ptr, True);    free(dock->icon_array);    if (dock->menu && dock->type!=WM_CLIP)        wMenuDestroy(dock->menu, True);    free(dock);}