heart : fix memory leak. 04/87404/3
authorKichan Kwon <k_c.kwon@samsung.com>
Thu, 8 Sep 2016 01:26:38 +0000 (10:26 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Tue, 20 Sep 2016 03:58:35 +0000 (12:58 +0900)
Change-Id: Idaf09623ef8d50a3bc041eadc3a4a58f1dcdc78a
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/heart/heart-cpu.c
src/heart/logging.c

index c240e8d..d33a6a1 100644 (file)
@@ -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);
                }
        }
index 3777f29..de729c8 100644 (file)
@@ -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");