From 2e87b20579e0f5e910102a971e4f84935e8b682c Mon Sep 17 00:00:00 2001 From: Dante Russo Date: Mon, 20 Mar 2017 15:04:36 -0700 Subject: [PATCH] Check Null on call to LocationAPI::addGeofence We need to handle the case where addGeofence returns Null, which can happen on error conditions, like when dlopen/dlsym libgeofence.so fails Bug: 36407968 CRs-fixed: 2022286 Change-Id: Ib612d92b77cf5532ad19154c57ee0545674d88f9 --- android/location_api/GeofenceAPIClient.cpp | 5 ++++- location/LocationAPIClientBase.cpp | 17 +++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/android/location_api/GeofenceAPIClient.cpp b/android/location_api/GeofenceAPIClient.cpp index 5be1cff2..ee4bfc38 100644 --- a/android/location_api/GeofenceAPIClient.cpp +++ b/android/location_api/GeofenceAPIClient.cpp @@ -100,7 +100,10 @@ void GeofenceAPIClient::geofenceAdd(uint32_t geofence_id, double latitude, doubl data.longitude = longitude; data.radius = radius_meters; - locAPIAddGeofences(1, &geofence_id, &options, &data); + LocationError err = (LocationError)locAPIAddGeofences(1, &geofence_id, &options, &data); + if (LOCATION_ERROR_SUCCESS != err) { + onAddGeofencesCb(1, &err, &geofence_id); + } } void GeofenceAPIClient::geofencePause(uint32_t geofence_id) diff --git a/location/LocationAPIClientBase.cpp b/location/LocationAPIClientBase.cpp index da56440b..6ced55a0 100644 --- a/location/LocationAPIClientBase.cpp +++ b/location/LocationAPIClientBase.cpp @@ -409,17 +409,18 @@ uint32_t LocationAPIClientBase::locAPIAddGeofences( delete requests; } uint32_t* sessions = mLocationAPI->addGeofences(count, options, data); - LOC_LOGI("%s:%d] start new sessions: %p", __FUNCTION__, __LINE__, sessions); - requests = new RequestQueue(-1); - requests->push(new AddGeofencesRequest(*this)); - mRequestQueues[REQUEST_GEOFENCE] = requests; + if (sessions) { + LOC_LOGI("%s:%d] start new sessions: %p", __FUNCTION__, __LINE__, sessions); + requests = new RequestQueue(-1); + requests->push(new AddGeofencesRequest(*this)); + mRequestQueues[REQUEST_GEOFENCE] = requests; - for (size_t i = 0; i < count; i++) { - mGeofenceBiDict.set(ids[i], sessions[i], options[i].breachTypeMask); + for (size_t i = 0; i < count; i++) { + mGeofenceBiDict.set(ids[i], sessions[i], options[i].breachTypeMask); + } + retVal = LOCATION_ERROR_SUCCESS; } pthread_mutex_unlock(&mMutex); - - retVal = LOCATION_ERROR_SUCCESS; } return retVal;