diff options
author | Daniel Jarai <daniel.jarai@bartec-pixavi.com> | 2018-09-18 16:49:19 +0200 |
---|---|---|
committer | Daniel Jarai <daniel.jarai@bartec-pixavi.com> | 2018-12-14 18:07:29 +0100 |
commit | 8880b727517b86b5472684d1330dc1c01449ce69 (patch) | |
tree | 8b34ceb0b5040abaf7963214906c2928dcf31a42 | |
parent | 5ef209c86344caedf23c09eb991e7434385cba96 (diff) | |
download | device_google_contexthub-android-o-mr1-iot-release-1.0.8.tar.gz device_google_contexthub-android-o-mr1-iot-release-1.0.8.tar.bz2 device_google_contexthub-android-o-mr1-iot-release-1.0.8.zip |
nanohub: hostIntf: handle memory allocation failuresandroid-o-mr1-iot-release-1.0.8
The memory allocations in hostIntf are quite big, and prone to failing
if there isn't enough available space. Make sure to handle failures, and
print an error, so we know what's happening.
Change-Id: Iddf014f1fb2889a358890c2308e6c0e93b59bf4e
-rw-r--r-- | firmware/os/core/hostIntf.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/firmware/os/core/hostIntf.c b/firmware/os/core/hostIntf.c index ccd571d8..c1d3cd0a 100644 --- a/firmware/os/core/hostIntf.c +++ b/firmware/os/core/hostIntf.c @@ -739,7 +739,18 @@ static bool initSensors() } mOutputQ = simpleQueueAlloc(totalBlocks, sizeof(struct HostIntfDataBuffer), queueDiscard); + if (!mOutputQ) { + osLog(LOG_ERROR, "initSensors: failed to allocate data buffer queue!\n"); + return false; + } + mActiveSensorTable = heapAlloc(numSensors * sizeof(struct ActiveSensor)); + if (!mActiveSensorTable) { + osLog(LOG_ERROR, "initSensors: failed to allocate active sensor table!\n"); + simpleQueueDestroy(mOutputQ); + return false; + } + memset(mActiveSensorTable, 0x00, numSensors * sizeof(struct ActiveSensor)); for (i = SENS_TYPE_INVALID; i < SENS_TYPE_LAST_USER; i++) { |