Skip to content

Commit edc1f21

Browse files
panvaaduh95
authored andcommitted
crypto: initialize KeyObjectData mutex eagerly
Create the mutex before sharing key data so every copy uses one lock. Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64851 Backport-PR-URL: #65087 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent be82372 commit edc1f21

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/crypto/crypto_keys.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,10 +953,13 @@ KeyObjectData::KeyObjectData(std::nullptr_t)
953953

954954
KeyObjectData::KeyObjectData(ByteSource symmetric_key)
955955
: key_type_(KeyType::kKeyTypeSecret),
956+
mutex_(std::make_shared<Mutex>()),
956957
data_(std::make_shared<Data>(std::move(symmetric_key))) {}
957958

958959
KeyObjectData::KeyObjectData(KeyType type, EVPKeyPointer&& pkey)
959-
: key_type_(type), data_(std::make_shared<Data>(std::move(pkey))) {}
960+
: key_type_(type),
961+
mutex_(std::make_shared<Mutex>()),
962+
data_(std::make_shared<Data>(std::move(pkey))) {}
960963

961964
void KeyObjectData::MemoryInfo(MemoryTracker* tracker) const {
962965
if (!*this) return;

0 commit comments

Comments
 (0)