msm8998: 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
(cherry picked from commit 47ef804c5ce51c14d73f045897edab30a2531fce)
diff --git a/msm8998/android/location_api/GeofenceAPIClient.cpp b/msm8998/android/location_api/GeofenceAPIClient.cpp
index 5be1cff..ee4bfc3 100644
--- a/msm8998/android/location_api/GeofenceAPIClient.cpp
+++ b/msm8998/android/location_api/GeofenceAPIClient.cpp
@@ -100,7 +100,10 @@
     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/msm8998/location/LocationAPIClientBase.cpp b/msm8998/location/LocationAPIClientBase.cpp
index 6a062eb..d007485 100644
--- a/msm8998/location/LocationAPIClientBase.cpp
+++ b/msm8998/location/LocationAPIClientBase.cpp
@@ -409,17 +409,18 @@
             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;