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>
diff --git a/libmemtrack/memtrack.cpp b/libmemtrack/memtrack.cpp
index e83f181..c5e74c1 100644
--- a/libmemtrack/memtrack.cpp
+++ b/libmemtrack/memtrack.cpp
@@ -31,6 +31,7 @@
 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 @@
     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 @@
                 t->records[i].flags = records[i].flags;
             }
     });
-    return err;
+    return ret.isOk() ? err : -1;
 }
 
 /* TODO: sanity checks on return values from HALs: