From f29a3523dc7d1894b0b53780ba2a72bf868910d7 Mon Sep 17 00:00:00 2001 From: Kichan Kwon Date: Thu, 8 Sep 2016 10:26:38 +0900 Subject: [PATCH] heart : fix memory leak. Change-Id: Idaf09623ef8d50a3bc041eadc3a4a58f1dcdc78a Signed-off-by: Kichan Kwon --- src/heart/heart-cpu.c | 4 ++-- src/heart/logging.c | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/heart/heart-cpu.c b/src/heart/heart-cpu.c index c240e8d..d33a6a1 100644 --- a/src/heart/heart-cpu.c +++ b/src/heart/heart-cpu.c @@ -1482,8 +1482,6 @@ static int heart_cpu_init(void *data) g_hash_table_iter_init(&iter, user_table); while (g_hash_table_iter_next(&iter, &key, &value)) { - uid = (int*)malloc(sizeof(int)); - *uid = *((int*)key); cache = (struct heart_cpu_dat_cache*)malloc(sizeof(struct heart_cpu_dat_cache)); cache->path = strndup((char*)value, strlen((char*)value)); cache->list = g_hash_table_new_full( @@ -1500,6 +1498,8 @@ static int heart_cpu_init(void *data) cache->last_file_commit_time = logging_get_time(CLOCK_BOOTTIME); + uid = (int*)malloc(sizeof(int)); + *uid = *((int*)key); g_hash_table_insert(heart_cpu_app_list, (gpointer)uid, (gpointer)cache); } } diff --git a/src/heart/logging.c b/src/heart/logging.c index 3777f29..de729c8 100644 --- a/src/heart/logging.c +++ b/src/heart/logging.c @@ -217,7 +217,7 @@ static void logging_free_queue(gpointer data) { struct logging_table_form *table = (struct logging_table_form*)data; if (table->data) - free(data); + free(table->data); free(table); } @@ -294,8 +294,6 @@ static int logging_update_user_db_list(char *name, enum logging_db_type type, GH g_hash_table_iter_init(&iter, user_table); while (g_hash_table_iter_next(&iter, &key, &value)) { - uid = (int*)malloc(sizeof(int)); - *uid = *((int*)key); home_dir = (char*)value; switch (type) { @@ -319,6 +317,9 @@ static int logging_update_user_db_list(char *name, enum logging_db_type type, GH _E("Fail to create user default DB"); return RESOURCED_ERROR_DB_FAILED; } + + uid = (int*)malloc(sizeof(int)); + *uid = *((int*)key); db_elem = (struct logging_db*)malloc(sizeof(struct logging_db)); db_elem->path = strndup(path, strlen(path)); db_elem->file = file; @@ -646,6 +647,7 @@ int logging_write(int pid, char *name, char *appid, char *pkgid, time_t time, ch break; } } + fclose(fp); if (uid == -1) { _E("There is no uid in the status file"); -- 2.7.4