[pim/akonadi] src/core: Destroy TagCache before QApplication
Volker Krause <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit c7d0d585e253a35526fd3f2defa41f3dd39f0aa4 by Volker Krause.
Committed on 10/08/2026 at 15:04.
Pushed by vkrause into branch 'master'.
Destroy TagCache before QApplication
If it still has active jobs it will crash otherwise.
Fixes two ASAN failures in kdepim-addons unit tests.
M +17 -2 src/core/tagcache.cpp
https://invent.kde.org/pim/akonadi/-/commit/c7d0d585e253a35526fd3f2defa41f3dd39f0aa4
diff --git a/src/core/tagcache.cpp b/src/core/tagcache.cpp
index 3d6d24c1c..5169c8551 100644
--- a/src/core/tagcache.cpp
+++ b/src/core/tagcache.cpp
@@ -13,6 +13,8 @@
#include <Akonadi/TagFetchScope>
#include <Akonadi/TagModifyJob>
+#include <QCoreApplication>
+
namespace Akonadi
{
class TagCachePrivate
@@ -115,8 +117,21 @@ void TagCache::setTagColor(const QString &tagName, const QColor &color)
TagCache *TagCache::instance()
{
- static TagCache s_instance;
- return &s_instance;
+ static std::unique_ptr<TagCache> s_instance;
+ if (QCoreApplication::closingDown()) {
+ return nullptr;
+ }
+ if (!s_instance) {
+ s_instance = std::make_unique<TagCache>();
+ connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, s_instance.get(), [&]() {
+ s_instance.reset();
+ });
+ // for QTest, we dont get aboutToQuit there
+ connect(QCoreApplication::instance(), &QObject::destroyed, s_instance.get(), [&]() {
+ s_instance.reset();
+ });
+ }
+ return s_instance.get();
}
#include "moc_tagcache.cpp"