return g_strcmp0(appid, app_time->app_id);
}
+void free_atm_st1(gpointer data)
+{
+ app_time_map_st1 *atm = (app_time_map_st1 *)data;
+
+ if (!atm)
+ return;
+
+ if (atm->app_id)
+ free(atm->app_id);
+ free(atm);
+}
+
bool is_running_app(const char *appid)
{
bool is_running = false;
if (!app_status) {
_D("%s is newly launched", appid);
new_app_status = malloc(sizeof(struct app_status));
+ if (!new_app_status) {
+ _E("malloc failed");
+ ret = BM_PLUGIN_ERROR_OUT_OF_MEMORY;
+ goto clean_atm;
+ }
new_app_status->pid = pid;
new_app_status->last_checkpoint = time;
new_app_status->used_time = utime + stime;
/* Insert the app using CPU in the ATM list */
if (!g_slist_find_custom(usage->atm_list, appid, find_app_time)) {
app_time_map = malloc(sizeof(app_time_map_st1));
+ if (!app_time_map) {
+ _E("malloc failed");
+ ret = BM_PLUGIN_ERROR_OUT_OF_MEMORY;
+ goto clean_atm;
+ }
app_time_map->app_id = g_strdup(appid);
+ if (!app_time_map->app_id) {
+ _E("g_strdup failed");
+ ret = BM_PLUGIN_ERROR_OUT_OF_MEMORY;
+ goto clean_atm;
+ }
app_time_map->time = tv.tv_sec - app_status->last_checkpoint;
if (app_time_map->time <= 0)
app_time_map->time = 1;
app_status->used_time = utime + stime;
app_status->last_status = status;
}
- sqlite3_finalize(stmt);
- sqlite3_close(db);
/* Update all running apps with current value */
g_hash_table_iter_init(&iter, running_app_list);
/* Insert the app using CPU in the ATM list */
if (!g_slist_find_custom(usage->atm_list, appid, find_app_time)) {
app_time_map = malloc(sizeof(app_time_map_st1));
+ if (!app_time_map) {
+ _E("malloc failed");
+ ret = BM_PLUGIN_ERROR_OUT_OF_MEMORY;
+ goto clean_atm;
+ }
app_time_map->app_id = g_strdup(appid);
+ if (!app_time_map->app_id) {
+ _E("g_strdup failed");
+ ret = BM_PLUGIN_ERROR_OUT_OF_MEMORY;
+ goto clean_atm;
+ }
app_time_map->time = tv.tv_sec - last_requested_time.tv_sec;
if (app_time_map->time <= 0)
app_time_map->time = 1;
*handle = usage;
_I("Succeed to get CPU usage");
+ ret = BM_PLUGIN_ERROR_NONE;
+ goto clean_db;
+
+clean_atm:
+ g_slist_free_full(usage->atm_list, free_atm_st1);
+
+clean_db:
+ sqlite3_finalize(stmt);
+ sqlite3_close(db);
+
EXIT;
- return BM_PLUGIN_ERROR_NONE;
+ return ret;
}
static bm_api_st cpu_api = {