Return before if Hash is NULL 07/244907/2
authorDewal Agarwal <d1.agarwal@samsung.com>
Fri, 25 Sep 2020 15:28:24 +0000 (20:58 +0530)
committerDewal Agarwal <d1.agarwal@samsung.com>
Fri, 25 Sep 2020 15:42:06 +0000 (21:12 +0530)
Change-Id: I92a9b22f73ea1dc7932342de38d3ff294aedcbad
Signed-off-by: Dewal Agarwal <d1.agarwal@samsung.com>
src/battery_dump/bd_history_item.c

index f3c7114b59b2cf36c2c90108b2686ede85d8cee0..569b7eb15ef8060c0e1f5afcf6fdfe41e2f1186f 100644 (file)
@@ -285,33 +285,34 @@ static int bd_get_and_print_battery_usage_from_dump(int fd, long int duration)
 
        g_string_free(dump_p, TRUE);
 
-       g_hash_table_iter_init(&iter, app_map);
-       while (g_hash_table_iter_next(&iter, &key, &value)) {
-               uid_n = (int *)key; appid = (char *)value;
-               _DBG("%d %s", *uid_n, appid); usageMAh = 0;
-               // Currently giving app usage of last one week;
-               // Modify it wrt to time
-               appid_usage_s *app_use = bm_server_query_app_usage_by_appid_ci(appid, duration, end_t, &ret);
-               if (app_use == NULL || ret != BATTERY_MONITOR_ERROR_NONE) {
-                       _ERR("For appid %s", appid);
-                       continue;
+       if (app_map != NULL) {
+               g_hash_table_iter_init(&iter, app_map);
+               while (g_hash_table_iter_next(&iter, &key, &value)) {
+                       uid_n = (int *)key; appid = (char *)value;
+                       _DBG("%d %s", *uid_n, appid); usageMAh = 0;
+                       appid_usage_s *app_use = bm_server_query_app_usage_by_appid_ci(appid, duration, end_t, &ret);
+                       if (app_use == NULL || ret != BATTERY_MONITOR_ERROR_NONE) {
+                               _ERR("For appid %s", appid);
+                               continue;
+                       }
+                       usageMAh = (app_use->rId_ble + app_use->rId_wifi + app_use->rId_cpu +
+                                       app_use->rId_display + app_use->rId_device_network +
+                                       app_use->rId_gps);
+                       // usage stored as mAs changed to mAh
+                       usageMAh = (usageMAh/3600);
+                       dump_p = g_string_sized_new(30);
+                       BM_CHECK_MEM_ALLOC(dump_p, { BM_FREE(app_use); });
+                       g_string_append_printf(dump_p, "%s,%d,l,pwi,uid,%0.2f\n",
+                       TIZEN_DUMP_VERSION, *uid_n, usageMAh);
+
+                       bm_appid_usage_free(app_use);
+                       _DBG("%s", dump_p->str);
+                       if (write(fd, dump_p->str, dump_p->len) < 0)
+                               _WARN("write error");
+                       g_string_free(dump_p, TRUE);
                }
-               usageMAh = (app_use->rId_ble + app_use->rId_wifi + app_use->rId_cpu +
-                               app_use->rId_display + app_use->rId_device_network +
-                               app_use->rId_gps);
-               // usage stored as mAs changed to mAh
-               usageMAh = (usageMAh/3600);
-               dump_p = g_string_sized_new(30);
-               BM_CHECK_MEM_ALLOC(dump_p, { BM_FREE(app_use); });
-               g_string_append_printf(dump_p, "%s,%d,l,pwi,uid,%0.2f\n",
-                               TIZEN_DUMP_VERSION, *uid_n, usageMAh);
-
-               bm_appid_usage_free(app_use);
-               _DBG("%s", dump_p->str);
-               if (write(fd, dump_p->str, dump_p->len) < 0)
-                       _WARN("write error");
-               g_string_free(dump_p, TRUE);
        }
+
        // Resource usage;
        const char *rid_str = NULL;
        for (int i = 0; i < 6; i++) {