Skip to content

Commit

Permalink
[qml-plugin-calendar] Protect the calendar manager teardown more. Con…
Browse files Browse the repository at this point in the history
…tributes to JB#51240

Avoid creating just to be deleted and avoid any chance of double
deletion.
  • Loading branch information
pvuorela committed Sep 15, 2020
1 parent 1ccc5ee commit 84c3233
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/calendarmanager.cpp
Expand Up @@ -98,9 +98,10 @@ CalendarManager::CalendarManager()
connect(mTimer, SIGNAL(timeout()), this, SLOT(timeout()));
}

static CalendarManager *managerInstance = nullptr;

CalendarManager *CalendarManager::instance(bool createIfNeeded)
{
static CalendarManager *managerInstance;
if (!managerInstance && createIfNeeded)
managerInstance = new CalendarManager;

Expand All @@ -111,6 +112,9 @@ CalendarManager::~CalendarManager()
{
mWorkerThread.quit();
mWorkerThread.wait();
if (managerInstance == this) {
managerInstance = nullptr;
}
}

QList<CalendarData::Notebook> CalendarManager::notebooks()
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.cpp
Expand Up @@ -97,7 +97,7 @@ class CalendarManagerReleaser: public QObject
// will be destroyed via deleteLater when control returns to the event loop.
// Deleting CalendarManager in NemoCalendarPlugin dtor is not an option
// as it is called after the event loop is stopped.
delete CalendarManager::instance();
delete CalendarManager::instance(false);
}
};

Expand Down

0 comments on commit 84c3233

Please sign in to comment.