Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.15.2
-
None
Description
In Qt it is a pattern that QCoreApplication, QGuiApplication and QApplication all call qt_call_post_routines() at the top of their destructor. This is essential to ensure that the post routines are invoked while the event dispatcher is still running or in more general terms, while it is still valid to send events. If an application subclasses one of the these three Qt-provided application classes and override QCoreApplication::notify() then it becomes subsceptible to a race condition at exit, where resources that are scheduled for clean up via qAddPostRoutine() are still alive after the SomeApplicationSubClass destructor has executed, but the Q*Application destructor has not. This must not be allowed because events send during this window will invoke SomeApplicationSubClass::notify() on a partially destroyed object. If the SomeApplicationSubClass::notify() method touches SomeApplicationSubClass data members this is likely to lead to a crash in practice too.
qt_call_post_routines() should be public API or there should be a public API added that calls it, e.g protected QCoreApplication::callPostRoutines(), and it should be documented that subclasses of QCoreApplication should call it in their destructor.