diff options
author | Saturneric <[email protected]> | 2022-12-04 07:44:29 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2022-12-04 07:44:29 +0000 |
commit | bf39cd6fb8a1716652b266c31778cfe865a5ba81 (patch) | |
tree | bd0c0aa64e8d6973c48d0da74d6a1f4017e31c55 | |
parent | fix: solve a crash issue (diff) | |
download | GpgFrontend-bf39cd6fb8a1716652b266c31778cfe865a5ba81.tar.gz GpgFrontend-bf39cd6fb8a1716652b266c31778cfe865a5ba81.zip |
fix: solve a refresh crash
-rw-r--r-- | src/core/model/GpgKey.cpp | 7 | ||||
-rw-r--r-- | src/core/model/GpgKey.h | 4 |
2 files changed, 10 insertions, 1 deletions
diff --git a/src/core/model/GpgKey.cpp b/src/core/model/GpgKey.cpp index ad88a649..4716d9cc 100644 --- a/src/core/model/GpgKey.cpp +++ b/src/core/model/GpgKey.cpp @@ -28,6 +28,8 @@ #include "core/model/GpgKey.h" +#include <mutex> + GpgFrontend::GpgKey::GpgKey(gpgme_key_t &&key) : key_ref_(std::move(key)) {} GpgFrontend::GpgKey::GpgKey(GpgKey &&k) noexcept { swap(key_ref_, k.key_ref_); } @@ -225,7 +227,10 @@ bool GpgFrontend::GpgKey::IsHasActualEncryptionCapability() const { } GpgFrontend::GpgKey GpgFrontend::GpgKey::Copy() const { - gpgme_key_ref(key_ref_.get()); + { + const std::lock_guard<std::mutex> guard(gpgme_key_opera_mutex); + gpgme_key_ref(key_ref_.get()); + } auto *_new_key_ref = key_ref_.get(); return GpgKey(std::move(_new_key_ref)); } diff --git a/src/core/model/GpgKey.h b/src/core/model/GpgKey.h index 4761f8a5..8c24ca5d 100644 --- a/src/core/model/GpgKey.h +++ b/src/core/model/GpgKey.h @@ -29,6 +29,8 @@ #ifndef GPGFRONTEND_GPGKEY_H #define GPGFRONTEND_GPGKEY_H +#include <mutex> + #include "GpgSubKey.h" #include "GpgUID.h" @@ -353,6 +355,8 @@ class GPGFRONTEND_CORE_EXPORT GpgKey { std::unique_ptr<struct _gpgme_key, _key_ref_deleter>; ///< KeyRefHandler key_ref_ = nullptr; ///< + + mutable std::mutex gpgme_key_opera_mutex; // mutex for gpgme key operations }; } // namespace GpgFrontend |