aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/utils/MemoryUtils.h
diff options
context:
space:
mode:
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