Skip to content

Commit

Permalink
backend, steamcompmgr: fix use-after-free issue at exit
Browse files Browse the repository at this point in the history
all: also release the xwayland_server_guard lock before calling pthread_exit() to prevent gamescope from hanging at exit
  • Loading branch information
sharkautarch committed Dec 1, 2024
1 parent 5cdf460 commit dd9068a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
19 changes: 7 additions & 12 deletions src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,29 @@ namespace gamescope
// IBackend
/////////////

static IBackend *s_pBackend = nullptr;
static std::atomic<IBackend*> s_pBackend = nullptr;

IBackend *IBackend::Get()
{
return s_pBackend;
}



bool IBackend::Set( IBackend *pBackend )
{
if ( s_pBackend )
{
delete s_pBackend;
s_pBackend = nullptr;
}

if ( pBackend )
{
s_pBackend = pBackend;
if ( !s_pBackend->Init() )
if ( !GetBackend()->Init() )
{
delete s_pBackend;
s_pBackend = nullptr;
s_pBackend = nullptr;
return false;
}
}

return true;
}


/////////////////
// CBaseBackendFb
Expand Down Expand Up @@ -184,4 +179,4 @@ namespace gamescope

GetBackend()->DumpDebugInfo();
});
}
}
8 changes: 5 additions & 3 deletions src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5896,7 +5896,7 @@ error(Display *dpy, XErrorEvent *ev)
}

[[noreturn]] static void
steamcompmgr_exit(void)
steamcompmgr_exit(std::optional<std::unique_lock<std::mutex>> lock = std::nullopt)
{
g_ImageWaiter.Shutdown();

Expand Down Expand Up @@ -5936,7 +5936,9 @@ steamcompmgr_exit(void)
wlserver_lock();
wlserver_shutdown();
wlserver_unlock(false);


if (lock)
lock->unlock();
pthread_exit(NULL);
}

Expand Down Expand Up @@ -8042,7 +8044,7 @@ steamcompmgr_main(int argc, char **argv)
vblank = false;
}

steamcompmgr_exit();
steamcompmgr_exit(std::optional<std::unique_lock<std::mutex>> {std::in_place_t{}, std::move(xwayland_server_guard)} );
}

void steamcompmgr_send_frame_done_to_focus_window()
Expand Down

0 comments on commit dd9068a

Please sign in to comment.