Merge "libbinder: keep ashmem size >= 0" am: 5805df43c8 am: 037f268d39
am: daf565333f
Change-Id: I7ac96936a6abb9e085a48d71bde16a2ed2fc9986
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 49592a8..a595c01 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -181,7 +181,10 @@
if ((outAshmemSize != nullptr) && ashmem_valid(obj.handle)) {
int size = ashmem_get_size_region(obj.handle);
if (size > 0) {
- *outAshmemSize -= size;
+ // ashmem size might have changed since last time it was accounted for, e.g.
+ // in acquire_object(). Value of *outAshmemSize is not critical since we are
+ // releasing the object anyway. Check for integer overflow condition.
+ *outAshmemSize -= std::min(*outAshmemSize, static_cast<size_t>(size));
}
}