From 3918c420b4d60fb463369a14ec6b832a8fa29310 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 31 Oct 2017 17:41:00 +0100 Subject: [PATCH] Check the active event loop in wxGenericProgressDialog dtor Verify that the active loop didn't change during this object lifetime as otherwise we could deactivate a different event loop from the one we installed. It's still a programming error to write code which doesn't destroy wxGenericProgressDialog early enough, but at least now "just" assert and leak memory in this case instead of resetting the active event loop and hanging the program. Closes #17983. --- src/generic/progdlgg.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/generic/progdlgg.cpp b/src/generic/progdlgg.cpp index 8a3c9ede12..03e1e7f933 100644 --- a/src/generic/progdlgg.cpp +++ b/src/generic/progdlgg.cpp @@ -697,6 +697,21 @@ wxGenericProgressDialog::~wxGenericProgressDialog() if ( m_tempEventLoop ) { + // If another event loop has been installed as active during the life + // time of this object, we shouldn't deactivate it, but we also can't + // delete our m_tempEventLoop in this case because it risks leaving the + // new event loop with a dangling pointer, which it will set back as + // the active loop when it exits, resulting in a crash. So we have no + // choice but to just leak this pointer then, which is, of course, bad + // and usually easily avoidable by just destroying the progress dialog + // sooner, so warn the programmer about it. + wxCHECK_RET + ( + wxEventLoopBase::GetActive() == m_tempEventLoop, + "current event loop must not be changed during " + "wxGenericProgressDialog lifetime" + ); + wxEventLoopBase::SetActive(NULL); delete m_tempEventLoop; }