Skip to content

Commit

Permalink
fix: discover and solve some memory issues
Browse files Browse the repository at this point in the history
  • Loading branch information
saturneric committed Jul 27, 2024
1 parent ca3a64b commit 1c44454
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions cmake/FlagsOverrides.cmake
Original file line number Diff line number Diff line change
@@ -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")
32 changes: 16 additions & 16 deletions src/core/module/GlobalRegisterTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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_;
Expand All @@ -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) {
Expand Down Expand Up @@ -232,8 +232,8 @@ class GlobalRegisterTableTreeModel::Impl {
return tr("<UNSUPPORTED>");
}

[[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()
Expand Down Expand Up @@ -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<std::any> {
auto GlobalRegisterTable::LookupKV(Namespace n,
Key v) -> std::optional<std::any> {
return p_->LookupKV(n, v);
}

Expand All @@ -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<Key> {
auto GlobalRegisterTable::ListChildKeys(Namespace n,
Key k) -> std::vector<Key> {
return p_->ListChildKeys(n, k);
}

GlobalRegisterTableTreeModel::GlobalRegisterTableTreeModel(
GlobalRegisterTable* grt)
: p_(SecureCreateUniqueObject<Impl>(this, grt->p_.get())) {}
GlobalRegisterTable* grt, QObject* parent)
: QAbstractItemModel(parent),
p_(SecureCreateUniqueObject<Impl>(this, grt->p_.get())) {}

auto GlobalRegisterTableTreeModel::rowCount(const QModelIndex& parent) const
-> int {
Expand All @@ -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);
}

Expand Down
7 changes: 4 additions & 3 deletions src/core/module/GlobalRegisterTableTreeModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/core/module/ModuleInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/module/ModuleManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/widgets/GRTTreeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 1c44454

Please sign in to comment.