WebSockets: fix crash when switching snapshots #9506

This commit is contained in:
Robin Gareus 2023-10-24 23:04:42 +02:00
parent e0f543d8fb
commit 1dbc3305fa
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 14 additions and 5 deletions

View File

@ -103,16 +103,22 @@ FeedbackHelperUI::FeedbackHelperUI()
: AbstractUI<BaseUI::BaseRequestObject> ("WS_FeedbackHelperUI")
{
// This renames and changes the event loop for the main thread, presumably
// this is not the actually desired behavior. If this is intentional, at
// least the event loop should be set back when this FeedbackHelperUI is
// destroyed, as otherwise future access to the event loop is likely going
// to crash.
// this is not the actually desired behavior.
char name[64];
snprintf (name, 64, "WS-%p", (void*)DEBUG_THREAD_SELF);
pthread_set_name (name);
/* The event loop needs to be restored when FeedbackHelperUI is destroyed,
* otherwise future access will result in a crash (heap-use-after-free).
*/
_main_event_loop = get_event_loop_for_thread ();
set_event_loop_for_thread (this);
}
FeedbackHelperUI::~FeedbackHelperUI ()
{
set_event_loop_for_thread (_main_event_loop);
}
void
FeedbackHelperUI::do_request (BaseUI::BaseRequestObject* req) {
if (req->type == CallSlot) {

View File

@ -36,11 +36,14 @@ class FeedbackHelperUI : public AbstractUI<BaseUI::BaseRequestObject>
{
public:
FeedbackHelperUI ();
~FeedbackHelperUI () {};
~FeedbackHelperUI ();
protected:
virtual void do_request (BaseUI::BaseRequestObject*);
private:
PBD::EventLoop* _main_event_loop;
};
class ArdourFeedback : public SurfaceComponent