fix: clean up envirnoment when app exits
This commit is contained in:
parent
f9a49043c3
commit
c41074792f
@ -31,14 +31,13 @@
|
||||
#include <memory>
|
||||
#include <shared_mutex>
|
||||
|
||||
#include "core/function/SecureMemoryAllocator.h"
|
||||
#include "core/function/basic/SingletonStorage.h"
|
||||
#include "core/utils/MemoryUtils.h"
|
||||
|
||||
namespace GpgFrontend {
|
||||
|
||||
std::unique_ptr<SingletonStorageCollection,
|
||||
SecureObjectDeleter<SingletonStorageCollection>>
|
||||
instance = nullptr;
|
||||
SecureUniquePtr<SingletonStorageCollection> global_instance = nullptr;
|
||||
|
||||
class SingletonStorageCollection::Impl {
|
||||
public:
|
||||
@ -48,12 +47,13 @@ class SingletonStorageCollection::Impl {
|
||||
* @return SingletonStorageCollection*
|
||||
*/
|
||||
static auto GetInstance(bool force_refresh) -> SingletonStorageCollection* {
|
||||
if (force_refresh || instance == nullptr) {
|
||||
instance = SecureCreateUniqueObject<SingletonStorageCollection>();
|
||||
SPDLOG_TRACE("a new single storage collection created, address: {}",
|
||||
static_cast<void*>(instance.get()));
|
||||
if (force_refresh || global_instance == nullptr) {
|
||||
global_instance = SecureCreateUniqueObject<SingletonStorageCollection>();
|
||||
SPDLOG_TRACE(
|
||||
"a new global singleton storage collection created, address: {}",
|
||||
static_cast<void*>(global_instance.get()));
|
||||
}
|
||||
return instance.get();
|
||||
return global_instance.get();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,7 +61,7 @@ class SingletonStorageCollection::Impl {
|
||||
*
|
||||
* @return SingletonStorageCollection*
|
||||
*/
|
||||
static void Destroy() { instance = nullptr; }
|
||||
static void Destroy() { global_instance = nullptr; }
|
||||
|
||||
/**
|
||||
* @brief Get the Singleton Storage object
|
||||
@ -100,7 +100,7 @@ class SingletonStorageCollection::Impl {
|
||||
};
|
||||
|
||||
SingletonStorageCollection::SingletonStorageCollection() noexcept
|
||||
: p_(std::make_unique<Impl>()) {}
|
||||
: p_(SecureCreateUniqueObject<Impl>()) {}
|
||||
|
||||
SingletonStorageCollection::~SingletonStorageCollection() = default;
|
||||
|
||||
@ -110,6 +110,9 @@ auto GpgFrontend::SingletonStorageCollection::GetInstance(bool force_refresh)
|
||||
}
|
||||
|
||||
void SingletonStorageCollection::Destroy() {
|
||||
SPDLOG_TRACE(
|
||||
"global singleton storage collection is about to destroy, address: {}",
|
||||
static_cast<void*>(global_instance.get()));
|
||||
return SingletonStorageCollection::Impl::Destroy();
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ class GPGFRONTEND_CORE_EXPORT SingletonStorageCollection {
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> p_;
|
||||
SecureUniquePtr<Impl> p_;
|
||||
};
|
||||
|
||||
} // namespace GpgFrontend
|
@ -45,7 +45,7 @@ class GlobalRegisterTable::Impl {
|
||||
public:
|
||||
struct RTNode {
|
||||
std::optional<std::any> value = std::nullopt;
|
||||
std::unordered_map<std::string, std::unique_ptr<RTNode>> children;
|
||||
std::unordered_map<std::string, SecureUniquePtr<RTNode>> children;
|
||||
int version = 0;
|
||||
const std::type_info* type = nullptr;
|
||||
};
|
||||
@ -61,12 +61,13 @@ class GlobalRegisterTable::Impl {
|
||||
{
|
||||
std::unique_lock lock(lock_);
|
||||
auto& root_rt_node =
|
||||
global_register_table_.emplace(n, std::make_unique<RTNode>())
|
||||
global_register_table_.emplace(n, SecureCreateUniqueObject<RTNode>())
|
||||
.first->second;
|
||||
|
||||
RTNode* current = root_rt_node.get();
|
||||
while (std::getline(iss, segment, '.')) {
|
||||
current = current->children.emplace(segment, std::make_unique<RTNode>())
|
||||
current = current->children
|
||||
.emplace(segment, SecureCreateUniqueObject<RTNode>())
|
||||
.first->second.get();
|
||||
}
|
||||
|
||||
@ -137,7 +138,7 @@ class GlobalRegisterTable::Impl {
|
||||
}
|
||||
|
||||
private:
|
||||
using Table = std::map<Namespace, std::unique_ptr<RTNode>>;
|
||||
using Table = std::map<Namespace, SecureUniquePtr<RTNode>>;
|
||||
std::shared_mutex lock_;
|
||||
GlobalRegisterTable* parent_;
|
||||
|
||||
|
@ -141,7 +141,7 @@ auto ListRTChildKeys(const std::string& namespace_, const std::string& key)
|
||||
|
||||
ModuleManager::ModuleManager(int channel)
|
||||
: SingletonFunctionObject<ModuleManager>(channel),
|
||||
p_(std::make_unique<Impl>()) {}
|
||||
p_(SecureCreateUniqueObject<Impl>()) {}
|
||||
|
||||
ModuleManager::~ModuleManager() = default;
|
||||
|
||||
|
@ -31,8 +31,10 @@
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#include "core/function/SecureMemoryAllocator.h"
|
||||
#include "core/function/basic/GpgFunctionObject.h"
|
||||
#include "core/module/Event.h"
|
||||
#include "core/utils/MemoryUtils.h"
|
||||
|
||||
namespace GpgFrontend::Thread {
|
||||
class TaskRunner;
|
||||
@ -86,7 +88,7 @@ class GPGFRONTEND_CORE_EXPORT ModuleManager
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> p_;
|
||||
SecureUniquePtr<Impl> p_;
|
||||
};
|
||||
|
||||
template <typename T, typename... Args>
|
||||
|
@ -199,6 +199,8 @@ void ShutdownGlobalBasicalEnv(const GFCxtWPtr &p_ctx) {
|
||||
|
||||
Thread::TaskRunnerGetter::GetInstance().StopAllTeakRunner();
|
||||
|
||||
DestroyGpgFrontendCore();
|
||||
|
||||
ShutdownLoggingSystem(ctx);
|
||||
}
|
||||
|
||||
|
13
src/init.h
13
src/init.h
@ -44,13 +44,13 @@ void HandleSignal(int sig);
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
void InitLoggingSystem(const GFCxtSPtr&);
|
||||
void InitLoggingSystem(const GFCxtSPtr &);
|
||||
|
||||
/**
|
||||
* @brief initialize the logging system.
|
||||
*
|
||||
*/
|
||||
void ShutdownLoggingSystem(const GFCxtSPtr&);
|
||||
void ShutdownLoggingSystem(const GFCxtSPtr &);
|
||||
|
||||
/**
|
||||
* @brief init global PATH env
|
||||
@ -63,6 +63,13 @@ void InitGlobalPathEnv();
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
void InitGlobalBasicalEnv(const GFCxtWPtr&, bool);
|
||||
void InitGlobalBasicalEnv(const GFCxtWPtr &, bool);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param p_ctx
|
||||
*/
|
||||
void ShutdownGlobalBasicalEnv(const GFCxtWPtr &p_ctx);
|
||||
|
||||
} // namespace GpgFrontend
|
10
src/main.cpp
10
src/main.cpp
@ -62,6 +62,7 @@ auto main(int argc, char* argv[]) -> int {
|
||||
GpgFrontend::GFCxtSPtr ctx =
|
||||
GpgFrontend::SecureCreateSharedObject<GpgFrontend::GpgFrontendContext>(
|
||||
argc, argv);
|
||||
auto rtn = 0;
|
||||
|
||||
// initialize qt resources
|
||||
Q_INIT_RESOURCE(gpgfrontend);
|
||||
@ -102,9 +103,14 @@ auto main(int argc, char* argv[]) -> int {
|
||||
ctx->load_default_gpg_context = false;
|
||||
|
||||
InitGlobalBasicalEnv(ctx, false);
|
||||
return RunTest(ctx);
|
||||
rtn = RunTest(ctx);
|
||||
ShutdownGlobalBasicalEnv(ctx);
|
||||
return rtn;
|
||||
}
|
||||
|
||||
InitGlobalBasicalEnv(ctx, true);
|
||||
return StartApplication(ctx);
|
||||
rtn = StartApplication(ctx);
|
||||
ShutdownGlobalBasicalEnv(ctx);
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user