From 8d0421de6049fad37ce859101070c790c7122412 Mon Sep 17 00:00:00 2001 From: Abhimanyu Swami Date: Mon, 23 Sep 2019 11:47:28 +0530 Subject: [PATCH] Resolved ASAN issues Change-Id: If704140344bda71e3257f7aed483b76f6507407f Signed-off-by: Abhimanyu Swami --- src/location_internal.c | 16 ++++++++++++---- src/locations.c | 23 ++++++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/location_internal.c b/src/location_internal.c index 054a4a0..ede0a44 100644 --- a/src/location_internal.c +++ b/src/location_internal.c @@ -179,8 +179,12 @@ int __set_callback(_location_event_e type, location_manager_h manager, void *cal LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(callback); location_manager_s *handle = (location_manager_s *) manager; - handle->user_cb[type] = callback; - handle->user_data[type] = user_data; + if (handle != NULL){ + handle->user_cb[type] = callback; + handle->user_data[type] = user_data; + } + else + LOCATIONS_LOGE("Null Handle"); LOCATIONS_LOGD("event type : %d", type); return LOCATIONS_ERROR_NONE; } @@ -189,8 +193,12 @@ int __unset_callback(_location_event_e type, location_manager_h manager) { LOCATIONS_NULL_ARG_CHECK(manager); location_manager_s *handle = (location_manager_s *) manager; - handle->user_cb[type] = NULL; - handle->user_data[type] = NULL; + if (handle != NULL){ + handle->user_cb[type] = NULL; + handle->user_data[type] = NULL; + } + else + LOCATIONS_LOGE("Null Handle"); LOCATIONS_LOGD("event type : %d", type); return LOCATIONS_ERROR_NONE; } diff --git a/src/locations.c b/src/locations.c index 36165c5..942f4c1 100755 --- a/src/locations.c +++ b/src/locations.c @@ -573,6 +573,7 @@ EXPORT_API int location_manager_destroy(location_manager_h manager) return __convert_error_code(ret); //LCOV_EXCL_LINE free(handle); + handle = NULL; return LOCATIONS_ERROR_NONE; } @@ -738,7 +739,10 @@ EXPORT_API int location_manager_get_method(location_manager_h manager, location_ location_manager_s *handle = (location_manager_s *) manager; LocationMethod _method = LOCATION_METHOD_NONE; - g_object_get(handle->object, "method", &_method, NULL); + if (handle != NULL) + g_object_get(handle->object, "method", &_method, NULL); + else + LOCATIONS_LOGE("Null Handle"); switch (_method) { case LOCATION_METHOD_NONE: *method = LOCATIONS_METHOD_NONE; @@ -952,7 +956,10 @@ EXPORT_API int location_manager_get_last_location(location_manager_h manager, do LocationPosition *last_pos = NULL; LocationVelocity *last_vel = NULL; LocationAccuracy *last_acc = NULL; - ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc); + if (handle != NULL) + ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc); + else + LOCATIONS_LOGE("Null Handle"); if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); //LCOV_EXCL_LINE @@ -1090,7 +1097,10 @@ EXPORT_API int location_manager_set_location_changed_cb(location_manager_h manag LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); LOCATIONS_NULL_ARG_CHECK(manager); location_manager_s *handle = (location_manager_s *) manager; - g_object_set(handle->object, "loc-interval", interval, NULL); + if (handle != NULL) + g_object_set(handle->object, "loc-interval", interval, NULL); + else + LOCATIONS_LOGE("Null Handle"); return __set_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager, callback, user_data); } @@ -1257,8 +1267,11 @@ EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea) LOCATIONS_NULL_ARG_CHECK(nmea); location_manager_s *handle = (location_manager_s *) manager; char *nmea_data; - - int ret = location_get_nmea(handle->object, &nmea_data); + int ret = 0; + if (handle != NULL) + ret = location_get_nmea(handle->object, &nmea_data); + else + LOCATIONS_LOGE("Null Handle"); if (ret != LOCATION_ERROR_NONE || nmea == NULL) { //LCOV_EXCL_START if (ret == LOCATION_ERROR_NOT_ALLOWED) { -- 2.7.4