From 1c4445408577a3bd5743d344cdd31f21d81dc9c0 Mon Sep 17 00:00:00 2001 From: saturneric Date: Sat, 27 Jul 2024 10:56:19 +0200 Subject: [PATCH] fix: discover and solve some memory issues --- CMakeLists.txt | 4 +-- cmake/FlagsOverrides.cmake | 4 +-- src/core/module/GlobalRegisterTable.cpp | 32 +++++++++---------- .../module/GlobalRegisterTableTreeModel.h | 7 ++-- src/core/module/ModuleInit.cpp | 3 +- src/core/module/ModuleManager.cpp | 6 ++-- src/ui/widgets/GRTTreeView.cpp | 2 +- third_party/CMakeLists.txt | 2 +- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c3aecc0..8d261fa5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -215,8 +215,8 @@ if(GPGFRONTEND_ENABLE_ASAN) message(FATAL_ERROR "Use GPGFRONTEND_ENABLE_ASAN only when using the clang compiler.") endif() - add_compile_options(-fsanitize=address) - add_link_options(-fsanitize=address) + add_compile_options(-fsanitize=address -fsanitize-recover=address) + add_link_options(-fsanitize=address -fsanitize-recover=address) set(ENABLE_ASAN 1) endif() diff --git a/cmake/FlagsOverrides.cmake b/cmake/FlagsOverrides.cmake index 8696c810..6c5c994c 100644 --- a/cmake/FlagsOverrides.cmake +++ b/cmake/FlagsOverrides.cmake @@ -1,11 +1,11 @@ SET (CMAKE_C_FLAGS "-Wall -std=c11") -SET (CMAKE_C_FLAGS_DEBUG "-g -fsanitize=address -fsanitize-recover=address") +SET (CMAKE_C_FLAGS_DEBUG "-g") SET (CMAKE_C_FLAGS_MINSIZERE "-Os -DNDEBUG") SET (CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG") SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g") SET (CMAKE_CXX_FLAGS "-Wall -std=c++17") -SET (CMAKE_CXX_FLAGS_DEBUG "-g -fsanitize=address -fsanitize-recover=address") +SET (CMAKE_CXX_FLAGS_DEBUG "-g") SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") SET (CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") \ No newline at end of file diff --git a/src/core/module/GlobalRegisterTable.cpp b/src/core/module/GlobalRegisterTable.cpp index bac51d85..c19a9131 100644 --- a/src/core/module/GlobalRegisterTable.cpp +++ b/src/core/module/GlobalRegisterTable.cpp @@ -126,8 +126,8 @@ class GlobalRegisterTable::Impl { return rtn; } - auto ListenPublish(QObject* o, const Namespace& n, const Key& k, LPCallback c) - -> bool { + auto ListenPublish(QObject* o, const Namespace& n, const Key& k, + LPCallback c) -> bool { if (o == nullptr) return false; return QObject::connect(parent_, &GlobalRegisterTable::SignalPublish, o, [n, k, c](const Namespace& pn, const Key& pk, @@ -138,7 +138,7 @@ class GlobalRegisterTable::Impl { }) == nullptr; } - auto RootRTNode() -> RTNode* { return root_node_.get(); } + auto RootRTNode() -> RTNodePtr { return root_node_; } private: std::shared_mutex lock_; @@ -165,8 +165,8 @@ class GlobalRegisterTableTreeModel::Impl { return 4; } - [[nodiscard]] auto Data(const QModelIndex& index, int role) const - -> QVariant { + [[nodiscard]] auto Data(const QModelIndex& index, + int role) const -> QVariant { if (!index.isValid()) return {}; if (role == Qt::DisplayRole) { @@ -232,8 +232,8 @@ class GlobalRegisterTableTreeModel::Impl { return tr(""); } - [[nodiscard]] auto Index(int row, int column, const QModelIndex& parent) const - -> QModelIndex { + [[nodiscard]] auto Index(int row, int column, + const QModelIndex& parent) const -> QModelIndex { if (!parent_->hasIndex(row, column, parent)) return {}; auto* parent_node = !parent.isValid() @@ -292,8 +292,8 @@ auto GlobalRegisterTable::PublishKV(Namespace n, Key k, std::any v) -> bool { return p_->PublishKV(n, k, v); } -auto GlobalRegisterTable::LookupKV(Namespace n, Key v) - -> std::optional { +auto GlobalRegisterTable::LookupKV(Namespace n, + Key v) -> std::optional { return p_->LookupKV(n, v); } @@ -302,14 +302,15 @@ auto GlobalRegisterTable::ListenPublish(QObject* o, Namespace n, Key k, return p_->ListenPublish(o, n, k, c); } -auto GlobalRegisterTable::ListChildKeys(Namespace n, Key k) - -> std::vector { +auto GlobalRegisterTable::ListChildKeys(Namespace n, + Key k) -> std::vector { return p_->ListChildKeys(n, k); } GlobalRegisterTableTreeModel::GlobalRegisterTableTreeModel( - GlobalRegisterTable* grt) - : p_(SecureCreateUniqueObject(this, grt->p_.get())) {} + GlobalRegisterTable* grt, QObject* parent) + : QAbstractItemModel(parent), + p_(SecureCreateUniqueObject(this, grt->p_.get())) {} auto GlobalRegisterTableTreeModel::rowCount(const QModelIndex& parent) const -> int { @@ -326,9 +327,8 @@ auto GlobalRegisterTableTreeModel::data(const QModelIndex& index, return p_->Data(index, role); } -auto GlobalRegisterTableTreeModel::index(int row, int column, - const QModelIndex& parent) const - -> QModelIndex { +auto GlobalRegisterTableTreeModel::index( + int row, int column, const QModelIndex& parent) const -> QModelIndex { return p_->Index(row, column, parent); } diff --git a/src/core/module/GlobalRegisterTableTreeModel.h b/src/core/module/GlobalRegisterTableTreeModel.h index fe4242a2..b7d56cc1 100644 --- a/src/core/module/GlobalRegisterTableTreeModel.h +++ b/src/core/module/GlobalRegisterTableTreeModel.h @@ -34,15 +34,16 @@ namespace GpgFrontend::Module { class GPGFRONTEND_CORE_EXPORT GlobalRegisterTableTreeModel : public QAbstractItemModel { public: - explicit GlobalRegisterTableTreeModel(GlobalRegisterTable *grt); + explicit GlobalRegisterTableTreeModel(GlobalRegisterTable *grt, + QObject *parent); [[nodiscard]] auto rowCount(const QModelIndex &parent) const -> int override; [[nodiscard]] auto columnCount(const QModelIndex &parent) const -> int override; - [[nodiscard]] auto data(const QModelIndex &index, int role) const - -> QVariant override; + [[nodiscard]] auto data(const QModelIndex &index, + int role) const -> QVariant override; [[nodiscard]] auto index(int row, int column, const QModelIndex &parent) const -> QModelIndex override; diff --git a/src/core/module/ModuleInit.cpp b/src/core/module/ModuleInit.cpp index 0e41e949..dc001798 100644 --- a/src/core/module/ModuleInit.cpp +++ b/src/core/module/ModuleInit.cpp @@ -68,14 +68,13 @@ auto LoadIntegratedMods() -> bool { } if (!QDir(mods_path).exists()) { - qCWarning(core) << "integrated module directory at path " << mods_path + qCWarning(core) << "integrated module directory at path: " << mods_path << " not found, abort..."; return false; } LoadModuleFromPath(mods_path, true); - qCDebug(core, "load integrated modules done."); return true; } diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index ad4f9ceb..45e9f657 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -60,9 +60,9 @@ class ModuleManager::Impl { [=](GpgFrontend::DataObjectPtr) -> int { QLibrary module_library(module_library_path); if (!module_library.load()) { - qCWarning(core) << "module manager failed to load module, " - "reason: broken library: " - << module_library.fileName(); + qCWarning(core) << "module manager failed to load module: " + << module_library.fileName() + << ", reason: " << module_library.errorString(); return -1; } diff --git a/src/ui/widgets/GRTTreeView.cpp b/src/ui/widgets/GRTTreeView.cpp index 09d7dcf0..b52f6881 100644 --- a/src/ui/widgets/GRTTreeView.cpp +++ b/src/ui/widgets/GRTTreeView.cpp @@ -35,7 +35,7 @@ namespace GpgFrontend::UI { GRTTreeView::GRTTreeView(QWidget* parent) : QTreeView(parent) { setModel(new Module::GlobalRegisterTableTreeModel( - Module::ModuleManager::GetInstance().GRT())); + Module::ModuleManager::GetInstance().GRT(), this)); connect(model(), &QFileSystemModel::layoutChanged, this, &GRTTreeView::slot_adjust_column_widths); diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 3c0b07ab..fa3fbf7a 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -47,7 +47,7 @@ if(${CMAKE_BUILD_TYPE} STREQUAL "Debug" AND ENABLE_ASAN) set(MI_OVERRIDE OFF) endif() - set(MI_TRACK_VALGRIND ON) + # set(MI_TRACK_VALGRIND ON) set(MI_TRACK_ASAN ON) endif()