libmemtrack: check return value for getMemory()

libmemtrack does not report an error when the binderized memtrack
service dies during a call to getMemory, so a crash in the memtrack
service can result in the calling process (e.g. system_server)
crashing as well. Add an error check to avoid this problem.

Bug: 35728498
Test: adb shell kill -9 $(adb shell pidof android.hardware.memtrack@1.0-service)
Change-Id: I852d8dfcbc1c92a95f8fe249b607dea8eb01f06a
Signed-off-by: Connor O'Brien <connoro@google.com>
This commit is contained in:
Connor O'Brien 2017-02-27 12:21:39 -08:00
parent 2aa94cfaf9
commit bbcf719f9a

View file

@ -31,6 +31,7 @@ using android::hardware::memtrack::V1_0::MemtrackRecord;
using android::hardware::memtrack::V1_0::MemtrackFlag;
using android::hardware::memtrack::V1_0::MemtrackStatus;
using android::hardware::hidl_vec;
using android::hardware::Return;
struct memtrack_proc_type {
MemtrackType type;
@ -69,7 +70,7 @@ static int memtrack_proc_get_type(memtrack_proc_type *t,
if (memtrack == nullptr)
return -1;
memtrack->getMemory(pid, type,
Return<void> ret = memtrack->getMemory(pid, type,
[&t, &err](MemtrackStatus status, hidl_vec<MemtrackRecord> records) {
if (status != MemtrackStatus::SUCCESS) {
err = -1;
@ -81,7 +82,7 @@ static int memtrack_proc_get_type(memtrack_proc_type *t,
t->records[i].flags = records[i].flags;
}
});
return err;
return ret.isOk() ? err : -1;
}
/* TODO: sanity checks on return values from HALs: