diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/core/GpgFrontendCore.cpp | 4 | ||||
-rw-r--r-- | src/core/function/SecureMemoryAllocator.cpp | 20 | ||||
-rw-r--r-- | src/core/function/gpg/GpgKeyOpera.cpp | 4 | ||||
-rw-r--r-- | src/core/thread/Task.cpp | 5 | ||||
-rw-r--r-- | src/test/core/GpgCoreTestKeygen.cpp | 9 |
6 files changed, 36 insertions, 12 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index cc207217..ee95b061 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -44,7 +44,9 @@ add_library(gpgfrontend_core SHARED ${CORE_SOURCE}) set(_export_file "${CMAKE_CURRENT_SOURCE_DIR}/GpgFrontendCoreExport.h") generate_export_header(gpgfrontend_core EXPORT_FILE_NAME "${_export_file}") -target_link_libraries(gpgfrontend_core PUBLIC mimalloc) +if(NOT APPLE) + target_link_libraries(gpgfrontend_core PUBLIC mimalloc) +endif() # link third-party libraries target_link_libraries(gpgfrontend_core PUBLIC config++) @@ -72,7 +74,7 @@ else () endif () # link gnupg libraries -target_link_libraries(gpgfrontend_core PRIVATE gpgme assuan gpg-error) +target_link_libraries(gpgfrontend_core PUBLIC gpgme assuan gpg-error) # link openssl target_link_libraries(gpgfrontend_core PUBLIC OpenSSL::SSL OpenSSL::Crypto) # link boost libraries diff --git a/src/core/GpgFrontendCore.cpp b/src/core/GpgFrontendCore.cpp index 5021b37d..2508f4e7 100644 --- a/src/core/GpgFrontendCore.cpp +++ b/src/core/GpgFrontendCore.cpp @@ -28,5 +28,7 @@ #include "core/GpgFrontendCore.h" +#ifndef MACOS // mimalloc -#include <mimalloc-new-delete.h>
\ No newline at end of file +#include <mimalloc-new-delete.h> +#endif diff --git a/src/core/function/SecureMemoryAllocator.cpp b/src/core/function/SecureMemoryAllocator.cpp index 2c584753..02efcbe0 100644 --- a/src/core/function/SecureMemoryAllocator.cpp +++ b/src/core/function/SecureMemoryAllocator.cpp @@ -28,19 +28,31 @@ #include "SecureMemoryAllocator.h" +#ifndef MACOS #include <mimalloc.h> +#endif namespace GpgFrontend { auto SecureMemoryAllocator::Allocate(std::size_t size) -> void* { +#ifndef MACOS auto* addr = mi_malloc(size); +#else + auto* addr = malloc(size); +#endif + SPDLOG_TRACE("secure memory allocator trys to alloc memory, address: {}", static_cast<void*>(addr)); return addr; } auto SecureMemoryAllocator::Reallocate(void* ptr, std::size_t size) -> void* { +#ifndef MACOS auto* addr = mi_realloc(ptr, size); +#else + auto* addr = realloc(ptr, size); +#endif + SPDLOG_TRACE( "secure memory allocator trys to realloc memory, " "old address: {}, new address: {}", @@ -48,6 +60,12 @@ auto SecureMemoryAllocator::Reallocate(void* ptr, std::size_t size) -> void* { return addr; } -void SecureMemoryAllocator::Deallocate(void* p) { mi_free(p); } +void SecureMemoryAllocator::Deallocate(void* p) { +#ifndef MACOS + mi_free(p); +#else + free(p); +#endif +} } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/function/gpg/GpgKeyOpera.cpp b/src/core/function/gpg/GpgKeyOpera.cpp index a89badc6..3ea9b365 100644 --- a/src/core/function/gpg/GpgKeyOpera.cpp +++ b/src/core/function/gpg/GpgKeyOpera.cpp @@ -199,9 +199,7 @@ void GpgKeyOpera::GenerateKey(const std::shared_ptr<GenKeyInfo>& params, GpgGenKeyResult result; if (CheckGpgError(err) == GPG_ERR_NO_ERROR) { - auto temp_result = - NewResult(gpgme_op_genkey_result(ctx.DefaultContext())); - std::swap(temp_result, result); + result = NewResult(gpgme_op_genkey_result(ctx.DefaultContext())); } data_object->Swap({result}); diff --git a/src/core/thread/Task.cpp b/src/core/thread/Task.cpp index a5d718ee..3b27e52f 100644 --- a/src/core/thread/Task.cpp +++ b/src/core/thread/Task.cpp @@ -177,8 +177,9 @@ class Task::Impl { SPDLOG_TRACE("task runnable {} finished, rtn: {}", GetFullID(), rtn); // set return value this->SetRTN(rtn); - +#ifdef RELEASE try { +#endif if (callback_) { SPDLOG_TRACE("task {} has a callback function", GetFullID()); if (callback_thread_ == QThread::currentThread()) { @@ -236,6 +237,7 @@ class Task::Impl { GetFullID()); emit parent_->SignalTaskEnd(); } +#ifdef RELEASE } catch (std::exception &e) { SPDLOG_ERROR("exception was caught at task callback: {}", e.what()); SPDLOG_ERROR( @@ -255,6 +257,7 @@ class Task::Impl { GetFullID()); emit parent_->SignalTaskEnd(); } +#endif } }; diff --git a/src/test/core/GpgCoreTestKeygen.cpp b/src/test/core/GpgCoreTestKeygen.cpp index aab400cb..f78f88dd 100644 --- a/src/test/core/GpgCoreTestKeygen.cpp +++ b/src/test/core/GpgCoreTestKeygen.cpp @@ -41,7 +41,7 @@ namespace GpgFrontend::Test { TEST_F(GpgCoreTest, GenerateKeyTest) { auto keygen_info = SecureCreateSharedObject<GenKeyInfo>(); - keygen_info->SetName("foo"); + keygen_info->SetName("foo_0"); keygen_info->SetEmail("[email protected]"); keygen_info->SetComment(""); keygen_info->SetKeyLength(1024); @@ -57,6 +57,7 @@ TEST_F(GpgCoreTest, GenerateKeyTest) { const DataObjectPtr& data_object) { ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR); + ASSERT_EQ(data_object->GetObjectSize(), 1); auto result = ExtractParams<GpgGenKeyResult>(data_object, 0); auto* fpr = result->fpr; auto key = @@ -79,7 +80,7 @@ TEST_F(GpgCoreTest, GenerateKeyTest) { TEST_F(GpgCoreTest, GenerateKeyTest_1) { auto keygen_info = SecureCreateSharedObject<GenKeyInfo>(); - keygen_info->SetName("foo"); + keygen_info->SetName("foo_1"); keygen_info->SetEmail("[email protected]"); keygen_info->SetComment("hello gpgfrontend"); keygen_info->SetAlgo(keygen_info->GetSupportedKeyAlgo()[0]); @@ -119,7 +120,7 @@ TEST_F(GpgCoreTest, GenerateKeyTest_1) { TEST_F(GpgCoreTest, GenerateKeyTest_4) { auto keygen_info = SecureCreateSharedObject<GenKeyInfo>(); - keygen_info->SetName("foo"); + keygen_info->SetName("foo_2"); keygen_info->SetEmail("[email protected]"); keygen_info->SetComment(""); keygen_info->SetAlgo(keygen_info->GetSupportedKeyAlgo()[1]); @@ -156,7 +157,7 @@ TEST_F(GpgCoreTest, GenerateKeyTest_4) { TEST_F(GpgCoreTest, GenerateKeyTest_5) { auto keygen_info = SecureCreateSharedObject<GenKeyInfo>(); - keygen_info->SetName("foo"); + keygen_info->SetName("foo_3"); keygen_info->SetEmail("[email protected]"); keygen_info->SetComment(""); keygen_info->SetAlgo(keygen_info->GetSupportedKeyAlgo()[2]); |