diff options
| author | 2020-09-25 19:51:03 +0000 | |
|---|---|---|
| committer | 2020-09-25 19:51:03 +0000 | |
| commit | d4ae5902a58ae2e00f6e6b32a8d7fd8a2d0f260c (patch) | |
| tree | c46ca2153df71b895dd47a6649d597046d8b046a | |
| parent | b4b99f5e8d7f9190237b9561f7c059288935cc50 (diff) | |
| parent | 1a27d7f55760a571566c931eae72a4610b91aa15 (diff) | |
Merge "libbinder_ndk: avoid need to allocate heap status" am: 9b1e10db73 am: 2133bd5454 am: 7a07f2fe76 am: 623a229a0c am: 1a27d7f557
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1434715
Change-Id: Ie663d8dda5be04a3f42bb439a39b835fb5c7abf0
| -rw-r--r-- | libs/binder/ndk/include_cpp/android/binder_auto_utils.h | 3 | ||||
| -rw-r--r-- | libs/binder/ndk/status.cpp | 7 |
2 files changed, 8 insertions, 2 deletions
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 f59bb75cc1..439b019665 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 @@ class ScopedAStatus : public impl::ScopedAResource<AStatus*, void, AStatus_delet 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 4fd59a21da..a8ae4411c6 100644 --- a/libs/binder/ndk/status.cpp +++ b/libs/binder/ndk/status.cpp @@ -23,7 +23,8 @@ using ::android::status_t; 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_deleteDescription(const char* description) { } void AStatus_delete(AStatus* status) { - delete status; + if (status != AStatus_newOk()) { + delete status; + } } binder_status_t PruneStatusT(status_t status) { |