fix memory leak 59/75259/5 accepted/tizen/common/20160620.163922 accepted/tizen/ivi/20160621.083829 accepted/tizen/mobile/20160621.083809 submit/tizen/20160620.101352
authorjomui <jongmun.woo@samsung.com>
Fri, 17 Jun 2016 07:12:34 +0000 (16:12 +0900)
committerjomui <jongmun.woo@samsung.com>
Fri, 17 Jun 2016 07:48:19 +0000 (16:48 +0900)
Signed-off-by: jomui <jongmun.woo@samsung.com>
Change-Id: Id9ff7c35fe00d7c1caee127189bf44ab6418de0f

geofence-server/src/geofence_server.c
geofence-server/src/geofence_server_db.c

index c5e68c1..9b4d66d 100644 (file)
@@ -1757,16 +1757,16 @@ static void dbus_update_place_cb(gint place_id, const gchar *app_id, const gchar
                return;
        }
 
-       place_info_s *place_info = (place_info_s *) g_malloc0(sizeof(place_info_s));
-       if (place_info == NULL) {
-               LOGI_GEOFENCE("malloc fail for place id[%d]", place_id);
-               __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_OUT_OF_MEMORY, GEOFENCE_MANAGE_PLACE_UPDATED);
-               return;
-       }
+       place_info_s *place_info = NULL;
        ret = geofence_manager_get_place_info(place_id, &place_info);
-       if (ret != FENCE_ERR_NONE) {
-               LOGI_GEOFENCE("Place_id does not exist or DB error in getting the place info for place_id[%d].", place_id);
-               __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_ID_NOT_EXIST, GEOFENCE_MANAGE_PLACE_UPDATED);
+       if (ret != FENCE_ERR_NONE || place_info == NULL) {
+               if (ret == FENCE_ERR_INTERNAL) {
+                       LOGI_GEOFENCE("malloc fail for place id[%d]", place_id);
+                       __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_OUT_OF_MEMORY, GEOFENCE_MANAGE_PLACE_UPDATED);
+               } else {
+                       LOGI_GEOFENCE("Place_id does not exist or DB error in getting the place info for place_id[%d].", place_id);
+                       __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_ID_NOT_EXIST, GEOFENCE_MANAGE_PLACE_UPDATED);
+               }
                g_free(place_info);
                return;
        }
@@ -1929,12 +1929,16 @@ static void dbus_remove_place_cb(gint place_id, const gchar *app_id, gpointer us
                return;
        }
 
-       place_info_s *place_info =
-           (place_info_s *) g_malloc0(sizeof(place_info_s));
+       place_info_s *place_info = NULL;
        ret = geofence_manager_get_place_info(place_id, &place_info);
-       if (ret != FENCE_ERR_NONE) {
-               LOGI_GEOFENCE("Place_id does not exist or DB error in getting the place info for place_id[%d].", place_id);
-               __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_ID_NOT_EXIST, GEOFENCE_MANAGE_PLACE_REMOVED);
+       if (ret != FENCE_ERR_NONE || place_info == NULL) {
+               if (ret == FENCE_ERR_INTERNAL) {
+                       LOGI_GEOFENCE("malloc fail for place id[%d]", place_id);
+                       __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_OUT_OF_MEMORY, GEOFENCE_MANAGE_PLACE_REMOVED);
+               } else {
+                       LOGI_GEOFENCE("Place_id does not exist or DB error in getting the place info for place_id[%d].", place_id);
+                       __emit_fence_event(geofence_server, place_id, -1, ACCESS_TYPE_UNKNOWN, app_id, GEOFENCE_SERVER_ERROR_ID_NOT_EXIST, GEOFENCE_MANAGE_PLACE_REMOVED);
+               }
                g_free(place_info);
                return;
        }
@@ -2434,12 +2438,16 @@ static GVariant *dbus_get_geofences_cb(int place_id, const gchar *app_id, int *f
                ret = geofence_manager_get_fence_list_from_db(&count, &fence_list, -1);
        } else {
                ret = geofence_manager_get_place_info(place_id, &place_info);
-               if (ret != FENCE_ERR_NONE) {
+               if (ret != FENCE_ERR_NONE || place_info == NULL) {
                        LOGE("Error getting the place info for place_id[%d]", place_id);
                        /* Send ZERO data gvariant*/
-                       *errorCode = GEOFENCE_SERVER_ERROR_DATABASE;
+                       if (ret == FENCE_ERR_INTERNAL)
+                               *errorCode = GEOFENCE_SERVER_ERROR_OUT_OF_MEMORY;
+                       else
+                               *errorCode = GEOFENCE_SERVER_ERROR_DATABASE;
                        *fenceCnt = fence_cnt;
                        g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
+                       g_free(place_info);
                        return g_variant_builder_end(&b);
                }
                if ((place_info != NULL) && (place_info->access_type == ACCESS_TYPE_PRIVATE)) {
index fabe33c..26273be 100755 (executable)
@@ -1359,7 +1359,7 @@ int geofence_manager_get_place_info(int place_id, place_info_s **place_info)
                return FENCE_ERR_SQLITE_FAIL;
        }
        *place_info = (place_info_s *)g_malloc0(sizeof(place_info_s));
-       g_return_val_if_fail(*place_info, FENCE_ERR_INVALID_PARAMETER);
+       g_return_val_if_fail(*place_info, FENCE_ERR_INTERNAL);
 
        data_name = (char *)sqlite3_column_text(state, ++index);
        if (!data_name || !strlen(data_name))