diff options
author | Baili Feng <bailif@codeaurora.org> | 2017-05-23 14:32:22 +0800 |
---|---|---|
committer | Dante Russo <drusso@codeaurora.org> | 2017-05-24 11:03:16 -0700 |
commit | b29778eac03901f616e2adda009bb68a42a376a9 (patch) | |
tree | e5442ee2a24eb2459894dfecb92366ac2d1cc397 /location/LocationAPIClientBase.h | |
parent | e3d70314b0001d54c4ad45e489ef905ffab65da5 (diff) | |
download | gps-b29778eac03901f616e2adda009bb68a42a376a9.tar.gz |
Fix intermittant crashes in location
Deleting memory without setting it to null
can cause the memory to still be non-null
and be interpreted as valid.
Also check if the entry is in the map using
find instead of assuming it is in the map.
Bug: 62033719 62033834 62033690 62033563 62032790
CRs-fixed: 2050837
Change-Id: I2534de2d6157be86ac95cfe6615e4c0019ee48fd
Diffstat (limited to 'location/LocationAPIClientBase.h')
-rw-r--r-- | location/LocationAPIClientBase.h | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/location/LocationAPIClientBase.h b/location/LocationAPIClientBase.h index 8bbaa3d..832dca8 100644 --- a/location/LocationAPIClientBase.h +++ b/location/LocationAPIClientBase.h @@ -197,19 +197,31 @@ private: } uint32_t getId(uint32_t session) { pthread_mutex_lock(&mBiDictMutex); - uint32_t ret = mBackwardMap[session]; + uint32_t ret = 0; + auto it = mBackwardMap.find(session); + if (it != mBackwardMap.end()) { + ret = it->second; + } pthread_mutex_unlock(&mBiDictMutex); return ret; } uint32_t getSession(uint32_t id) { pthread_mutex_lock(&mBiDictMutex); - uint32_t ret = mForwardMap[id]; + uint32_t ret = 0; + auto it = mForwardMap.find(id); + if (it != mForwardMap.end()) { + ret = it->second; + } pthread_mutex_unlock(&mBiDictMutex); return ret; } uint32_t getType(uint32_t session) { pthread_mutex_lock(&mBiDictMutex); - uint32_t ret = mTypeMap[session]; + uint32_t ret = 0; + auto it = mTypeMap.find(session); + if (it != mTypeMap.end()) { + ret = it->second; + } pthread_mutex_unlock(&mBiDictMutex); return ret; } |