aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/utils/MemoryUtils.h
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-01-12 06:02:37 +0000
committersaturneric <[email protected]>2024-01-12 06:02:37 +0000
commitbf538056b24a68b8fd235b1c50991ee8eb46a776 (patch)
treee1bab54095b80df62b321fb5bd69453f9f951b05 /src/core/utils/MemoryUtils.h
parentfeat: improve api and ui of keys import and export (diff)
downloadGpgFrontend-bf538056b24a68b8fd235b1c50991ee8eb46a776.tar.gz
GpgFrontend-bf538056b24a68b8fd235b1c50991ee8eb46a776.zip
refactor: use QString instead of std::string and improve threading system
Diffstat (limited to 'src/core/utils/MemoryUtils.h')
-rw-r--r--src/core/utils/MemoryUtils.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/core/utils/MemoryUtils.h b/src/core/utils/MemoryUtils.h
index 800f2163..76c75fc6 100644
--- a/src/core/utils/MemoryUtils.h
+++ b/src/core/utils/MemoryUtils.h
@@ -159,4 +159,21 @@ auto SecureCreateSharedObject(Args &&...args) -> std::shared_ptr<T> {
}
}
+template <typename T, typename... Args>
+auto SecureCreateQSharedObject(Args &&...args) -> QSharedPointer<T> {
+ void *mem = SecureMemoryAllocator::Allocate(sizeof(T));
+ if (!mem) throw std::bad_alloc();
+
+ try {
+ T *obj = new (mem) T(std::forward<Args>(args)...);
+ return QSharedPointer<T>(obj, [](T *ptr) {
+ ptr->~T();
+ SecureMemoryAllocator::Deallocate(ptr);
+ });
+ } catch (...) {
+ SecureMemoryAllocator::Deallocate(mem);
+ throw;
+ }
+}
+
}; // namespace GpgFrontend \ No newline at end of file