aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2023-12-16 05:41:38 +0000
committersaturneric <[email protected]>2023-12-16 05:41:38 +0000
commitd6311ece3fa3e8e976befa7e253d453398046c7c (patch)
treea23183865059d06ee7796214d9747b8bf334016c
parentfix: clean up envirnoment when app exits (diff)
downloadGpgFrontend-d6311ece3fa3e8e976befa7e253d453398046c7c.tar.gz
GpgFrontend-d6311ece3fa3e8e976befa7e253d453398046c7c.zip
fix: slove memory problem of gpg context
-rw-r--r--src/GpgFrontendContext.h3
-rw-r--r--src/core/function/GlobalSettingStation.cpp8
-rw-r--r--src/core/function/gpg/GpgContext.cpp24
-rw-r--r--src/core/function/gpg/GpgContext.h6
-rw-r--r--src/test/GpgFrontendTest.cpp23
5 files changed, 28 insertions, 36 deletions
diff --git a/src/GpgFrontendContext.h b/src/GpgFrontendContext.h
index 34bd46f0..baa2c7a7 100644
--- a/src/GpgFrontendContext.h
+++ b/src/GpgFrontendContext.h
@@ -28,9 +28,6 @@
#pragma once
-#include <qapplication.h>
-#include <qcoreapplication.h>
-
#include "core/function/SecureMemoryAllocator.h"
namespace GpgFrontend {
diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp
index d1c1068e..b54fbfd3 100644
--- a/src/core/function/GlobalSettingStation.cpp
+++ b/src/core/function/GlobalSettingStation.cpp
@@ -36,15 +36,13 @@
namespace GpgFrontend {
-class GlobalSettingStation::Impl
- : SingletonFunctionObject<GlobalSettingStation::Impl> {
+class GlobalSettingStation::Impl {
public:
/**
* @brief Construct a new Global Setting Station object
*
*/
- explicit Impl(int channel) noexcept
- : SingletonFunctionObject<GlobalSettingStation::Impl>(channel) {
+ explicit Impl() noexcept {
SPDLOG_INFO("app path: {}", app_path_.u8string());
SPDLOG_INFO("app configure path: {}", app_configure_path_.u8string());
SPDLOG_INFO("app data path: {}", app_data_path_.u8string());
@@ -269,7 +267,7 @@ class GlobalSettingStation::Impl
GlobalSettingStation::GlobalSettingStation(int channel) noexcept
: SingletonFunctionObject<GlobalSettingStation>(channel),
- p_(std::make_unique<Impl>(channel)) {}
+ p_(std::make_unique<Impl>()) {}
GlobalSettingStation::~GlobalSettingStation() noexcept = default;
diff --git a/src/core/function/gpg/GpgContext.cpp b/src/core/function/gpg/GpgContext.cpp
index f7223e13..7cde439c 100644
--- a/src/core/function/gpg/GpgContext.cpp
+++ b/src/core/function/gpg/GpgContext.cpp
@@ -280,14 +280,12 @@ class GpgContext::Impl {
assert(p_ctx != nullptr);
binary_ctx_ref_ = p_ctx;
- // if (!common_ctx_initialize(binary_ctx_ref_, args)) {
- // SPDLOG_ERROR("get new ctx failed, binary");
- // return false;
- // }
-
- // /** Setting the output type must be done at the beginning */
- // /** think this means ascii-armor --> ? */
- // gpgme_set_armor(binary_ctx_ref_, 0);
+ if (!common_ctx_initialize(binary_ctx_ref_, args)) {
+ SPDLOG_ERROR("get new ctx failed, binary");
+ return false;
+ }
+
+ gpgme_set_armor(binary_ctx_ref_, 0);
return true;
}
@@ -300,11 +298,11 @@ class GpgContext::Impl {
assert(p_ctx != nullptr);
ctx_ref_ = p_ctx;
- // if (!common_ctx_initialize(ctx_ref_, args)) {
- // return false;
- // }
+ if (!common_ctx_initialize(ctx_ref_, args)) {
+ return false;
+ }
- // gpgme_set_armor(ctx_ref_, 1);
+ gpgme_set_armor(ctx_ref_, 1);
return true;
}
};
@@ -313,7 +311,7 @@ GpgContext::GpgContext(int channel)
: SingletonFunctionObject<GpgContext>(channel),
p_(SecureCreateUniqueObject<Impl>(this, GpgContextInitArgs{})) {}
-GpgContext::GpgContext(const GpgContextInitArgs &args, int channel)
+GpgContext::GpgContext(GpgContextInitArgs args, int channel)
: SingletonFunctionObject<GpgContext>(channel),
p_(SecureCreateUniqueObject<Impl>(this, args)) {}
diff --git a/src/core/function/gpg/GpgContext.h b/src/core/function/gpg/GpgContext.h
index ead0c89b..16dd7c4a 100644
--- a/src/core/function/gpg/GpgContext.h
+++ b/src/core/function/gpg/GpgContext.h
@@ -55,13 +55,11 @@ struct GpgContextInitArgs {
*
*/
class GPGFRONTEND_CORE_EXPORT GpgContext
- : public QObject,
- public SingletonFunctionObject<GpgContext> {
- Q_OBJECT
+ : public SingletonFunctionObject<GpgContext> {
public:
explicit GpgContext(int channel);
- explicit GpgContext(const GpgContextInitArgs &args, int channel);
+ explicit GpgContext(GpgContextInitArgs args, int channel);
virtual ~GpgContext() override;
diff --git a/src/test/GpgFrontendTest.cpp b/src/test/GpgFrontendTest.cpp
index 7b318aec..b356a380 100644
--- a/src/test/GpgFrontendTest.cpp
+++ b/src/test/GpgFrontendTest.cpp
@@ -36,8 +36,10 @@
#include <boost/dll.hpp>
#include <filesystem>
+#include "core/GpgConstants.h"
#include "core/GpgCoreInit.h"
#include "core/function/GlobalSettingStation.h"
+#include "core/function/basic/ChannelObject.h"
#include "core/function/gpg/GpgContext.h"
#include "spdlog/spdlog.h"
@@ -107,17 +109,16 @@ void ConfigureGpgContext() {
std::filesystem::create_directory(db_path);
}
- // GpgContext::CreateInstance(
- // kGpgFrontendDefaultChannel, [&]() -> ChannelObjectPtr {
- // GpgContextInitArgs args;
- // args.test_mode = true;
- // args.offline_mode = true;
- // args.db_path = db_path.string();
-
- // return
- // ConvertToChannelObjectPtr<>(SecureCreateUniqueObject<GpgContext>(
- // args, kGpgFrontendDefaultChannel));
- // });
+ GpgContext::CreateInstance(
+ kGpgFrontendDefaultChannel, [=]() -> ChannelObjectPtr {
+ GpgContextInitArgs args;
+ args.test_mode = true;
+ args.offline_mode = true;
+ args.db_path = db_path.string();
+
+ return ConvertToChannelObjectPtr<>(SecureCreateUniqueObject<GpgContext>(
+ args, kGpgFrontendDefaultChannel));
+ });
}
auto ExecuteAllTestCase(GpgFrontendContext args) -> int {