From 8880b727517b86b5472684d1330dc1c01449ce69 Mon Sep 17 00:00:00 2001 From: Daniel Jarai Date: Tue, 18 Sep 2018 16:49:19 +0200 Subject: nanohub: hostIntf: handle memory allocation failures 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 --- firmware/os/core/hostIntf.c | 11 +++++++++++ 1 file changed, 11 insertions(+) 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++) { -- cgit v1.2.3