From 9d6392d3794f4127ed590a0bc291cadfdab1ba7d Mon Sep 17 00:00:00 2001 From: Roel Standaert Date: Thu, 23 Jul 2020 13:33:35 +0200 Subject: [PATCH] Add a fix from Wt 3 If WTimer outlives timerRoot_, this would cause a segfault, so a WTimer could not reliably be the child of WApplication. --- src/Wt/WApplication.C | 10 ++++++++++ src/Wt/WObject.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/Wt/WApplication.C b/src/Wt/WApplication.C index 283f858f2b..8feae00fce 100644 --- a/src/Wt/WApplication.C +++ b/src/Wt/WApplication.C @@ -381,6 +381,16 @@ std::string WApplication::onePixelGifUrl() WApplication::~WApplication() { #ifndef WT_TARGET_JAVA + // Fix issue #5331: if WTimer is a child of WApplication, + // it will outlive timerRoot_. Delete it now already. + for (std::size_t i = 0; i < children_.size(); ++i) { + WTimer *timer = dynamic_cast(children_[i].get()); + if (timer) { + removeChild(timer); + } + } + timerRoot_ = nullptr; + // First remove all children owned by this WApplication (issue #6282) if (domRoot_) { auto domRoot = domRoot_.get(); diff --git a/src/Wt/WObject.h b/src/Wt/WObject.h index 10f2ee6dbb..3a9558f587 100644 --- a/src/Wt/WObject.h +++ b/src/Wt/WObject.h @@ -339,6 +339,7 @@ class WT_API WObject : public Wt::Core::observable static unsigned nextObjId_; friend class EventSignalBase; + friend class WApplication; friend class WebSession; };