wayland: fix double-free crash when destroying shared WApplication
When main_window_desc is the real WWindow (found via wWindowFor rather than created by makeMainWindow), wApplicationDestroy must not call wWindowDestroy on it — the window is still managed and will be destroyed by wUnmanageWindow. Add shared_main_desc flag to track ownership.
This commit is contained in:
parent
29550b58cb
commit
5325a51b64
|
|
@ -117,7 +117,9 @@ WApplication *wApplicationCreate(WWindow * wwin)
|
||||||
/* If the main_window is also the client window (Wayland native apps),
|
/* If the main_window is also the client window (Wayland native apps),
|
||||||
* reuse the existing WWindow which already has a frame. */
|
* reuse the existing WWindow which already has a frame. */
|
||||||
wapp->main_window_desc = wWindowFor(main_window);
|
wapp->main_window_desc = wWindowFor(main_window);
|
||||||
if (!wapp->main_window_desc) {
|
if (wapp->main_window_desc) {
|
||||||
|
wapp->flags.shared_main_desc = 1;
|
||||||
|
} else {
|
||||||
wapp->main_window_desc = makeMainWindow(scr, main_window);
|
wapp->main_window_desc = makeMainWindow(scr, main_window);
|
||||||
if (!wapp->main_window_desc) {
|
if (!wapp->main_window_desc) {
|
||||||
wfree(wapp);
|
wfree(wapp);
|
||||||
|
|
@ -194,14 +196,15 @@ void wApplicationDestroy(WApplication *wapp)
|
||||||
/* Remove application icon */
|
/* Remove application icon */
|
||||||
removeAppIconFor(wapp);
|
removeAppIconFor(wapp);
|
||||||
|
|
||||||
|
if (!wapp->flags.shared_main_desc) {
|
||||||
wwin = wWindowFor(wapp->main_window_desc->client_win);
|
wwin = wWindowFor(wapp->main_window_desc->client_win);
|
||||||
|
|
||||||
wWindowDestroy(wapp->main_window_desc);
|
wWindowDestroy(wapp->main_window_desc);
|
||||||
if (wwin) {
|
if (wwin) {
|
||||||
/* undelete client window context that was deleted in
|
/* undelete client window context that was deleted in
|
||||||
* wWindowDestroy */
|
* wWindowDestroy */
|
||||||
wm_backend->context_save(wwin->client_win, WM_CTX_CLIENT_WIN, &wwin->client_descriptor);
|
wm_backend->context_save(wwin->client_win, WM_CTX_CLIENT_WIN, &wwin->client_descriptor);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
wfree(wapp);
|
wfree(wapp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ typedef struct WApplication {
|
||||||
unsigned int hidden:1;
|
unsigned int hidden:1;
|
||||||
unsigned int emulated:1;
|
unsigned int emulated:1;
|
||||||
unsigned int bouncing:1;
|
unsigned int bouncing:1;
|
||||||
|
unsigned int shared_main_desc:1;
|
||||||
} flags;
|
} flags;
|
||||||
} WApplication;
|
} WApplication;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue