commit | 7a07f2fe767212e69a94c50944ebb8a583db903d | [log] [tgz] |
---|---|---|
author | Steven Moreland <smoreland@google.com> | Fri Sep 25 18:29:58 2020 +0000 |
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | Fri Sep 25 18:29:58 2020 +0000 |
tree | 76faaba44304d7af39439b30582f0cf73f4233fe | |
parent | 1e75f59587f7758bb3f159948256d769dc4a8027 [diff] | |
parent | 2133bd545481e66223c4c3c40946cc1ef0798135 [diff] |
Merge "libbinder_ndk: avoid need to allocate heap status" am: 9b1e10db73 am: 2133bd5454 Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1434715 Change-Id: I3da056cdfc75a144798a439cefe0631f8a2bdeda
diff --git a/libs/binder/ndk/include_cpp/android/binder_auto_utils.h b/libs/binder/ndk/include_cpp/android/binder_auto_utils.h index f59bb75..439b019 100644 --- a/libs/binder/ndk/include_cpp/android/binder_auto_utils.h +++ b/libs/binder/ndk/include_cpp/android/binder_auto_utils.h
@@ -199,6 +199,9 @@ public: /** * Takes ownership of a. + * + * WARNING: this constructor is only expected to be used when reading a + * status value. Use `ScopedAStatus::ok()` instead. */ explicit ScopedAStatus(AStatus* a = nullptr) : ScopedAResource(a) {} ~ScopedAStatus() {}
diff --git a/libs/binder/ndk/status.cpp b/libs/binder/ndk/status.cpp index 4fd59a2..a8ae441 100644 --- a/libs/binder/ndk/status.cpp +++ b/libs/binder/ndk/status.cpp
@@ -23,7 +23,8 @@ using ::android::binder::Status; AStatus* AStatus_newOk() { - return new AStatus(); + static AStatus status = AStatus(); + return &status; } AStatus* AStatus_fromExceptionCode(binder_exception_t exception) { @@ -78,7 +79,9 @@ } void AStatus_delete(AStatus* status) { - delete status; + if (status != AStatus_newOk()) { + delete status; + } } binder_status_t PruneStatusT(status_t status) {