diff options
author | saturneric <[email protected]> | 2023-12-13 12:02:24 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2023-12-13 12:02:34 +0000 |
commit | d74765b42206a83c0ade8617e8100794eb169f37 (patch) | |
tree | 531352a75e4996c2a51cdb53b070515cd5596f53 /src | |
parent | fix: add some logs in setting channel object (diff) | |
download | GpgFrontend-d74765b42206a83c0ade8617e8100794eb169f37.tar.gz GpgFrontend-d74765b42206a83c0ade8617e8100794eb169f37.zip |
feat: mimalloc support valgrind
Diffstat (limited to 'src')
-rw-r--r-- | src/core/function/SecureMemoryAllocator.cpp | 6 | ||||
-rw-r--r-- | src/core/function/SecureMemoryAllocator.h | 7 | ||||
-rw-r--r-- | src/core/function/basic/SingletonStorage.cpp | 2 | ||||
-rw-r--r-- | src/core/utils/MemoryUtils.cpp | 6 | ||||
-rw-r--r-- | src/core/utils/MemoryUtils.h | 20 |
5 files changed, 22 insertions, 19 deletions
diff --git a/src/core/function/SecureMemoryAllocator.cpp b/src/core/function/SecureMemoryAllocator.cpp index e213ccbc..b9201942 100644 --- a/src/core/function/SecureMemoryAllocator.cpp +++ b/src/core/function/SecureMemoryAllocator.cpp @@ -32,14 +32,14 @@ namespace GpgFrontend { -auto SecurityMemoryAllocator::Allocate(std::size_t size) -> void* { +auto SecureMemoryAllocator::Allocate(std::size_t size) -> void* { auto* addr = mi_malloc(size); SPDLOG_TRACE("secure memory allocator trys to alloc memory, address: {}", static_cast<void*>(addr)); return addr; } -auto SecurityMemoryAllocator::Reallocate(void* ptr, std::size_t size) -> void* { +auto SecureMemoryAllocator::Reallocate(void* ptr, std::size_t size) -> void* { auto* addr = mi_realloc(ptr, size); SPDLOG_TRACE( "secure memory allocator trys to realloc memory, " @@ -48,7 +48,7 @@ auto SecurityMemoryAllocator::Reallocate(void* ptr, std::size_t size) -> void* { return addr; } -void SecurityMemoryAllocator::Deallocate(void* p) { +void SecureMemoryAllocator::Deallocate(void* p) { SPDLOG_TRACE("secure memory allocator trys to free memory, address: {}", static_cast<void*>(p)); mi_free(p); diff --git a/src/core/function/SecureMemoryAllocator.h b/src/core/function/SecureMemoryAllocator.h index 1475e258..a0905ba7 100644 --- a/src/core/function/SecureMemoryAllocator.h +++ b/src/core/function/SecureMemoryAllocator.h @@ -32,7 +32,7 @@ namespace GpgFrontend { -class GPGFRONTEND_CORE_EXPORT SecurityMemoryAllocator { +class GPGFRONTEND_CORE_EXPORT SecureMemoryAllocator { public: static auto Allocate(std::size_t) -> void *; @@ -45,9 +45,10 @@ template <typename T> struct SecureObjectDeleter { void operator()(T *ptr) { if (ptr) { - SPDLOG_TRACE("secure object deleter trys to free object, obj: {}", static_cast<void *>(ptr)); + SPDLOG_TRACE("secure object deleter trys to free object, obj: {}", + static_cast<void *>(ptr)); ptr->~T(); - SecurityMemoryAllocator::Deallocate(ptr); + SecureMemoryAllocator::Deallocate(ptr); } } }; diff --git a/src/core/function/basic/SingletonStorage.cpp b/src/core/function/basic/SingletonStorage.cpp index 2497cec4..211a51b3 100644 --- a/src/core/function/basic/SingletonStorage.cpp +++ b/src/core/function/basic/SingletonStorage.cpp @@ -76,6 +76,8 @@ class SingletonStorage::Impl { assert(p_obj != nullptr); if (p_obj == nullptr) { + SPDLOG_ERROR("cannot set a nullptr as a channel obejct of channel: {}", + channel); return nullptr; } diff --git a/src/core/utils/MemoryUtils.cpp b/src/core/utils/MemoryUtils.cpp index eae9fa10..f002fd87 100644 --- a/src/core/utils/MemoryUtils.cpp +++ b/src/core/utils/MemoryUtils.cpp @@ -31,12 +31,12 @@ namespace GpgFrontend { auto SecureMalloc(std::size_t size) -> void * { - return SecurityMemoryAllocator::Allocate(size); + return SecureMemoryAllocator::Allocate(size); } auto SecureRealloc(void *ptr, std::size_t size) -> void * { - return SecurityMemoryAllocator::Reallocate(ptr, size); + return SecureMemoryAllocator::Reallocate(ptr, size); } -void SecureFree(void *ptr) { SecurityMemoryAllocator::Deallocate(ptr); } +void SecureFree(void *ptr) { SecureMemoryAllocator::Deallocate(ptr); } } // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/utils/MemoryUtils.h b/src/core/utils/MemoryUtils.h index 5261a958..6cbbfec8 100644 --- a/src/core/utils/MemoryUtils.h +++ b/src/core/utils/MemoryUtils.h @@ -88,7 +88,7 @@ auto GPGFRONTEND_CORE_EXPORT SecureRealloc(void *, std::size_t) -> void *; */ template <typename T> auto SecureMallocAsType(std::size_t size) -> T * { - return PointerConverter<T>(SecurityMemoryAllocator::Allocate(size)).AsType(); + return PointerConverter<T>(SecureMemoryAllocator::Allocate(size)).AsType(); } /** @@ -98,7 +98,7 @@ auto SecureMallocAsType(std::size_t size) -> T * { */ template <typename T> auto SecureReallocAsType(T *ptr, std::size_t size) -> T * { - return PointerConverter<T>(SecurityMemoryAllocator::Reallocate(ptr, size)) + return PointerConverter<T>(SecureMemoryAllocator::Reallocate(ptr, size)) .AsType(); } @@ -110,7 +110,7 @@ void GPGFRONTEND_CORE_EXPORT SecureFree(void *); template <typename T, typename... Args> static auto SecureCreateObject(Args &&...args) -> T * { - void *mem = SecurityMemoryAllocator::Allocate(sizeof(T)); + void *mem = SecureMemoryAllocator::Allocate(sizeof(T)); if (!mem) return nullptr; SPDLOG_TRACE("alloc secure memnory success, mem: {}", static_cast<void *>(mem)); @@ -118,7 +118,7 @@ static auto SecureCreateObject(Args &&...args) -> T * { try { return new (mem) T(std::forward<Args>(args)...); } catch (...) { - SecurityMemoryAllocator::Deallocate(mem); + SecureMemoryAllocator::Deallocate(mem); throw; } } @@ -129,13 +129,13 @@ static void SecureDestroyObject(T *obj) { SPDLOG_TRACE("try to free object, obj: {}", static_cast<void *>(obj)); obj->~T(); - SecurityMemoryAllocator::Deallocate(obj); + SecureMemoryAllocator::Deallocate(obj); } template <typename T, typename... Args> static auto SecureCreateUniqueObject(Args &&...args) -> std::unique_ptr<T, SecureObjectDeleter<T>> { - void *mem = SecurityMemoryAllocator::Allocate(sizeof(T)); + void *mem = SecureMemoryAllocator::Allocate(sizeof(T)); if (!mem) throw std::bad_alloc(); SPDLOG_TRACE("alloc secure memnory success, unique ptr, type: {}, mem: {}", typeid(T).name(), mem); @@ -144,14 +144,14 @@ static auto SecureCreateUniqueObject(Args &&...args) return std::unique_ptr<T, SecureObjectDeleter<T>>( new (mem) T(std::forward<Args>(args)...)); } catch (...) { - SecurityMemoryAllocator::Deallocate(mem); + SecureMemoryAllocator::Deallocate(mem); throw; } } template <typename T, typename... Args> auto SecureCreateSharedObject(Args &&...args) -> std::shared_ptr<T> { - void *mem = SecurityMemoryAllocator::Allocate(sizeof(T)); + void *mem = SecureMemoryAllocator::Allocate(sizeof(T)); if (!mem) throw std::bad_alloc(); SPDLOG_TRACE("alloc secure memnory success, shared ptr, type: {}, mem: {}", typeid(T).name(), mem); @@ -160,10 +160,10 @@ auto SecureCreateSharedObject(Args &&...args) -> std::shared_ptr<T> { T *obj = new (mem) T(std::forward<Args>(args)...); return std::shared_ptr<T>(obj, [](T *ptr) { ptr->~T(); - SecurityMemoryAllocator::Deallocate(ptr); + SecureMemoryAllocator::Deallocate(ptr); }); } catch (...) { - SecurityMemoryAllocator::Deallocate(mem); + SecureMemoryAllocator::Deallocate(mem); throw; } } |