Keystore 2.0: km_compat: Fix ref counting in software keymint device.
CreateKeyMintDevice now creates a shared_ptr with correct ref counts.
Bug: 219791936
Test: atest keystore2_km_compat_test_cpp does not crash any more.
Change-Id: I3b304c0a4d55883b8f917ce0ef4c70d4bd0e9e9b
diff --git a/keystore2/src/km_compat/km_compat.cpp b/keystore2/src/km_compat/km_compat.cpp
index 0775f2f..3db1a9f 100644
--- a/keystore2/src/km_compat/km_compat.cpp
+++ b/keystore2/src/km_compat/km_compat.cpp
@@ -1420,7 +1420,7 @@
setNumFreeSlots(15);
}
- softKeyMintDevice_.reset(CreateKeyMintDevice(KeyMintSecurityLevel::SOFTWARE));
+ softKeyMintDevice_ = CreateKeyMintDevice(KeyMintSecurityLevel::SOFTWARE);
}
sp<Keymaster> getDevice(KeyMintSecurityLevel securityLevel) {
@@ -1448,7 +1448,7 @@
static std::shared_ptr<IKeyMintDevice> swDevice;
std::lock_guard<std::mutex> lock(mutex);
if (!swDevice) {
- swDevice.reset(CreateKeyMintDevice(KeyMintSecurityLevel::SOFTWARE));
+ swDevice = CreateKeyMintDevice(KeyMintSecurityLevel::SOFTWARE);
}
return swDevice;
}