Catch more allocation failure cases
Bug: 216213939
Bug: 215451239
Test: VtsAidlKeyMintTargetTest
Ignore-AOSP-First: Cherry pick from AOSP
Change-Id: I604c980dba7644e4012a358b6f2dc204cb215c3c
(cherry picked from commit 01d2e13c563a82e5cb0dc1adacd0ca5b41322497)
diff --git a/ng/AndroidSharedSecret.cpp b/ng/AndroidSharedSecret.cpp
index b2cb85d..c800666 100644
--- a/ng/AndroidSharedSecret.cpp
+++ b/ng/AndroidSharedSecret.cpp
@@ -46,6 +46,9 @@
ComputeSharedHmacRequest request(impl_->message_version());
request.params_array.params_array =
new (std::nothrow) keymaster::HmacSharingParameters[params.size()];
+ if (request.params_array.params_array == nullptr) {
+ return kmError2ScopedAStatus(KM_ERROR_MEMORY_ALLOCATION_FAILED);
+ }
request.params_array.num_params = params.size();
for (size_t i = 0; i < params.size(); ++i) {
request.params_array.params_array[i].seed = {params[i].seed.data(), params[i].seed.size()};