SVACE FIXS 27/199527/3 accepted/tizen/unified/20190214.060711 submit/tizen/20190213.103117
authorAvichal <avichal.a@samsung.com>
Tue, 12 Feb 2019 12:02:29 +0000 (17:32 +0530)
committerAvichal <avichal.a@samsung.com>
Wed, 13 Feb 2019 06:17:38 +0000 (11:47 +0530)
WGIDS: 370880,370928,370929,370931,370932,370933,370934,370936,
370938,370939,370940,370941,370942

Change-Id: I0c54ca2901747b5af8fbd4a25abd24cd847760e8
Signed-off-by: Avichal <avichal.a@samsung.com>
geofence-server/src/geofence_server_db.c

index 3a6a340..fd1e969 100755 (executable)
@@ -67,12 +67,13 @@ static struct {
        .handle = NULL,
 };
 
-#define SQLITE3_RETURN(ret, msg, state) \
+#define SQLITE3_RETURN(ret, msg, state, query) \
        if (ret != SQLITE_OK) { \
                LOGI_GEOFENCE("sqlite3 Error[%d] : %s", ret, msg); \
                sqlite3_reset(state); \
                sqlite3_clear_bindings(state); \
                sqlite3_finalize(state); \
+               sqlite3_free(query); \
                return FENCE_ERR_SQLITE_FAIL; \
        }
 
@@ -351,6 +352,7 @@ static int __geofence_manager_db_insert_bssid_info(const int fence_id, char *bss
        }
        if (count > 0) {
                LOGI_GEOFENCE("count = %d", count);
+               sqlite3_free(query);
                return FENCE_ERR_NONE;
        }
 
@@ -362,13 +364,13 @@ static int __geofence_manager_db_insert_bssid_info(const int fence_id, char *bss
        }
 
        ret = sqlite3_bind_int(state, ++index, fence_id);
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = sqlite3_bind_text(state, ++index, bssid_info, -1, SQLITE_STATIC);
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = sqlite3_bind_text(state, ++index, ssid, -1, SQLITE_STATIC);
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = sqlite3_step(state);
        if (ret != SQLITE_DONE) {
@@ -420,10 +422,10 @@ static int __geofence_manager_db_insert_wifi_data_info(gpointer data, gpointer u
        }
 
        ret = sqlite3_bind_int(state, ++index, *fence_id);
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = sqlite3_bind_text(state, ++index, wifi_info->bssid, -1, SQLITE_STATIC);
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = sqlite3_step(state);
        if (ret != SQLITE_DONE) {
@@ -772,13 +774,13 @@ int geofence_manager_set_place_info(place_info_s *place_info, int *place_id)
        LOGD_GEOFENCE("appid[%s] access_type[%d] place_name[%s]", place_info->appid, place_info->access_type, place_info->place_name);
 
        ret = sqlite3_bind_int(state, ++index, place_info->access_type);
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = sqlite3_bind_text(state, ++index, place_info->place_name, -1, SQLITE_STATIC);
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = sqlite3_bind_text(state, ++index, place_info->appid, -1, SQLITE_STATIC);
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = sqlite3_step(state);
        if (ret != SQLITE_DONE) {
@@ -823,22 +825,22 @@ int geofence_manager_set_common_info(fence_common_info_s *fence_info, int *fence
        LOGD_GEOFENCE("place_id[%d], enable[%d], appid[%s] geofence_type[%d] access_type[%d] running_status[%d]", fence_info->place_id, fence_info->enable, fence_info->appid, fence_info->type, fence_info->access_type, fence_info->running_status);
 
        ret = sqlite3_bind_int(state, ++index, fence_info->place_id);
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = sqlite3_bind_int(state, ++index, fence_info->enable);
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = sqlite3_bind_text(state, ++index, fence_info->appid, -1, SQLITE_STATIC);
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = sqlite3_bind_int(state, ++index, fence_info->type);
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = sqlite3_bind_int(state, ++index, fence_info->access_type);
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = sqlite3_bind_int(state, ++index, fence_info->running_status);
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = sqlite3_step(state);
        if (ret != SQLITE_DONE) {
@@ -1130,7 +1132,7 @@ int geofence_manager_set_geocoordinate_info(int fence_id, geocoordinate_info_s *
        }
 
        ret = sqlite3_bind_int(state, ++index, fence_id);
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
 #ifdef SUPPORT_ENCRYPTION
        if (password == NULL)
@@ -1142,36 +1144,39 @@ int geofence_manager_set_geocoordinate_info(int fence_id, geocoordinate_info_s *
        ret = sqlite3_bind_text(state, ++index, data_name_lat, -1, SQLITE_STATIC);
 
        /*ret = sqlite3_bind_double (state, ++index, geocoordinate_info->latitude);*/
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = snprintf(data_name_lon, MAX_DATA_NAME, "%lf", geocoordinate_info->longitude);
        if (ret < 0) {
                LOGD_GEOFENCE("ERROR: String will be truncated");
+               sqlite3_free(query);
                sqlite3_finalize(state);
                return FENCE_ERR_STRING_TRUNCATED;
        }
 
        ret = sqlite3_bind_text(state, ++index, data_name_lon, -1, SQLITE_STATIC);
        /*ret = sqlite3_bind_double (state, ++index, geocoordinate_info->longitude);*/
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = snprintf(data_name_rad, MAX_DATA_NAME, "%lf", geocoordinate_info->radius);
        if (ret < 0) {
                LOGD_GEOFENCE("ERROR: String will be truncated");
+               sqlite3_free(query);
                sqlite3_finalize(state);
                return FENCE_ERR_STRING_TRUNCATED;
        }
 
        ret = sqlite3_bind_text(state, ++index, data_name_rad, -1, SQLITE_STATIC);
        /*ret = sqlite3_bind_double (state, ++index, geocoordinate_info->radius);*/
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = sqlite3_bind_text(state, ++index, geocoordinate_info->address, -1, SQLITE_STATIC);
-       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state);
+       SQLITE3_RETURN(ret, sqlite3_errmsg(db_info_s.handle), state, query);
 
        ret = sqlite3_step(state);
        if (ret != SQLITE_DONE) {
                LOGI_GEOFENCE("sqlite3_step Error[%d] : %s", ret, sqlite3_errmsg(db_info_s.handle));
+               sqlite3_free(query);
                sqlite3_finalize(state);
                return FENCE_ERR_SQLITE_FAIL;
        }
@@ -1221,6 +1226,7 @@ int geofence_manager_get_geocoordinate_info(int fence_id, geocoordinate_info_s *
        *geocoordinate_info = (geocoordinate_info_s *)g_malloc0(sizeof(geocoordinate_info_s));
        if (*geocoordinate_info ==  NULL) {
                sqlite3_finalize(state);
+               sqlite3_free(query);
        }
        g_return_val_if_fail(*geocoordinate_info, FENCE_ERR_INVALID_PARAMETER);
 
@@ -1320,6 +1326,7 @@ int geofence_manager_get_ap_info(const int fence_id, GList **ap_list)
                }
                wifi_info = g_slice_new0(wifi_info_s);
                if (wifi_info == NULL) {
+                       sqlite3_free(query2);
                        sqlite3_finalize(state);
                }
                g_return_val_if_fail(wifi_info, -1);
@@ -1368,6 +1375,7 @@ int geofence_manager_get_place_info(int place_id, place_info_s **place_info)
        }
        *place_info = (place_info_s *)g_malloc0(sizeof(place_info_s));
        if (*place_info == NULL) {
+               sqlite3_free(query);
                sqlite3_finalize(state);
        }
        g_return_val_if_fail(*place_info, FENCE_ERR_INTERNAL);
@@ -1483,6 +1491,7 @@ int geofence_manager_get_bssid_info(const int fence_id, bssid_info_s **bssid_inf
                }
                bssid_info_from_db = g_slice_new0(bssid_info_s);
                if (bssid_info_from_db == NULL) {
+                       sqlite3_free(query2);
                        sqlite3_finalize(state);
                }
                g_return_val_if_fail(bssid_info_from_db, -1);
@@ -2054,6 +2063,10 @@ int geofence_manager_get_access_type(int fence_id, int place_id, access_type_e *
 
        LOGD_GEOFENCE("current fence id is [%d]", fence_id);
        LOGD_GEOFENCE("current place id is [%d]", place_id);
+
+       if (query == NULL)
+               return FENCE_ERR_INVALID_PARAMETER;
+
        ret = sqlite3_prepare_v2(db_info_s.handle, query, -1, &state, &tail);
        if (ret != SQLITE_OK) {
                LOGI_GEOFENCE("Error: %s", sqlite3_errmsg(db_info_s.handle));
@@ -2543,6 +2556,7 @@ int geofence_manager_get_count_by_params(const char *app_id, geofence_type_e fen
        if (*count <= 0) {
                LOGI_GEOFENCE("ERROR: count = %d", *count);
                sqlite3_finalize(state);
+               sqlite3_free(query);
                return FENCE_ERR_COUNT;
        } else {
                LOGI_GEOFENCE("count[%d]", *count);
@@ -2640,6 +2654,7 @@ int geofence_manager_get_count_of_fences(int *count)
        if (*count < 0) {
                LOGI_GEOFENCE("ERROR: count = %d", *count);
                sqlite3_finalize(state);
+               sqlite3_free(query);
                return FENCE_ERR_COUNT;
        } else {
                LOGI_GEOFENCE("count[%d]", *count);
@@ -2679,6 +2694,7 @@ int geofence_manager_get_place_count_by_placeid(int place_id, int *count)
        if (*count < 0) {
                LOGI_GEOFENCE("ERROR: place count = %d", *count);
                sqlite3_finalize(state);
+               sqlite3_free(query);
                return FENCE_ERR_COUNT;
        } else {
                LOGI_GEOFENCE("place count[%d]", *count);