bm_server_db: Free member before freeing structure 22/318322/1 accepted/tizen_9.0_unified tizen_9.0 accepted/tizen/9.0/unified/20250116.154312
authorUnsung Lee <unsung.lee@samsung.com>
Mon, 13 Jan 2025 03:28:28 +0000 (12:28 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Wed, 15 Jan 2025 10:34:08 +0000 (19:34 +0900)
Free member in the structure before freeing structure.
This is because the member cannot be found after freeing the strucutre.
In addition, remove a duplicate code which makes null pointer.

Change-Id: Id7f2c901c65485015b88bec6be10ff0276f95b5e
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/bm_server_db.c

index 24923a252eb6ddf0a43b9b5794508e2fa7587eef..7e3597fc95794dc7d6542605df7787c5baccaf46 100755 (executable)
@@ -1550,8 +1550,8 @@ CATCH:
                hstmt = NULL;
        }
        if ((*error_code != BATTERY_MONITOR_ERROR_NONE) && bm_app_type) {
+               BM_FREE(bm_app_type->AppId);
                BM_FREE(bm_app_type);
-               bm_app_type = NULL;
        }
        if ((*error_code == BATTERY_MONITOR_ERROR_NONE) && bm_app_type != NULL) {
                _INFO("Returning appid usage");
@@ -1769,8 +1769,8 @@ CATCH:
                hstmt = NULL;
        }
        if ((*error_code != BATTERY_MONITOR_ERROR_NONE) && bm_resource_type) {
+               BM_FREE(bm_resource_type->ResourceId);
                BM_FREE(bm_resource_type);
-               bm_resource_type = NULL;
        }
        if ((*error_code == BATTERY_MONITOR_ERROR_NONE) && bm_resource_type != NULL) {
                _INFO("Returning appid usage");
@@ -1832,8 +1832,8 @@ CATCH:
                hstmt = NULL;
        }
        if ((*error_code != BATTERY_MONITOR_ERROR_NONE) && bm_resource_type) {
+               BM_FREE(bm_resource_type->ResourceId);
                BM_FREE(bm_resource_type);
-               bm_resource_type = NULL;
        }
        if ((*error_code == BATTERY_MONITOR_ERROR_NONE) && bm_resource_type != NULL) {
                _INFO("Returning appid usage");
@@ -1894,7 +1894,6 @@ CATCH:
        }
        if ((*error_code != BATTERY_MONITOR_ERROR_NONE) && bm_resource_type) {
                BM_FREE(bm_resource_type);
-               bm_resource_type = NULL;
        }
        if ((*error_code == BATTERY_MONITOR_ERROR_NONE) && bm_resource_type != NULL) {
                _INFO("Returning battery plug time");