emul_state: freed memories those are allocated in runtime
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 18 Aug 2015 07:29:09 +0000 (16:29 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Wed, 19 Aug 2015 04:33:05 +0000 (13:33 +0900)
Change-Id: I5546cd3f680dc5b253a05235228ed60fbd6f00e5
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
tizen/src/emul_state.c
tizen/src/emul_state.h
tizen/src/emulator.c

index 42d0afa..3ea18a7 100644 (file)
@@ -53,6 +53,7 @@ extern bool hax_allowed;
 #include "qmp-commands.h"
 #include "fsdev/qemu-fsdev.h"
 
+#include "emulator.h"
 #include "emulator_options.h"
 #include "hw/virtio/maru_virtio_touchscreen.h"
 #include "hw/virtio/maru_virtio_evdi.h"
@@ -359,15 +360,19 @@ const char *launch_conf_file = NULL;
 
 // bin path
 // only set by osutil-{OS}.c when start up
-const char *bin_path = "";
+const char *bin_path = NULL;
 
 const char *get_bin_path(void)
 {
-    return bin_path;
+    if (bin_path) {
+        return bin_path;
+    }
+
+    return "";
 }
 
 // emulator kernel log file
-static const char *kernel_log_redirect_file;
+static const char *kernel_log_redirect_file = NULL;
 
 const char *get_kernel_log_redirect_file(void)
 {
@@ -392,7 +397,7 @@ const char *get_kernel_log_redirect_file(void)
 }
 
 // emulator log file
-static const char *log_redirect_file;
+static const char *log_redirect_file = NULL;
 
 #ifdef CONFIG_WIN32
 // for checking Windows version
@@ -517,7 +522,7 @@ const char *get_http_proxy_addr(void)
         g_strfreev(token);
     }
 
-    http_proxy_addr = "";
+    http_proxy_addr = g_strdup("");
 
     LOG_INFO("HTTP proxy address is not set.\n");
 
@@ -817,3 +822,37 @@ bool is_skin_enabled(void)
     return skin_enabled;
 }
 #endif
+
+static void emul_state_notify_exit(Notifier *notifier, void *data)
+{
+    g_free((void *)launch_conf_file);
+    launch_conf_file = NULL;
+
+    g_free((void *)bin_path);
+    bin_path = NULL;
+
+    g_free((void *)kernel_log_redirect_file);
+    kernel_log_redirect_file = NULL;
+
+    g_free((void *)log_redirect_file);
+    log_redirect_file = NULL;
+
+    g_free((void *)drive_image_file);
+    drive_image_file = NULL;
+
+    g_free((void *)http_proxy_addr);
+    http_proxy_addr = NULL;
+
+    g_free((void *)vm_name);
+    vm_name = NULL;
+
+    g_free((void *)vm_data_path);
+    vm_data_path = NULL;
+}
+
+static Notifier emul_state_exit = { .notify = emul_state_notify_exit };
+
+void init_emul_state(void)
+{
+    emulator_add_exit_notifier(&emul_state_exit);
+}
index 45bbdae..8aef4c8 100644 (file)
@@ -206,4 +206,5 @@ bool is_skin_enabled(void);
 void set_vm_data_path(const char *path);
 #endif
 
+void init_emul_state(void);
 #endif /* __EMUL_STATE_H__ */
index 485b74a..a6baba5 100644 (file)
@@ -380,6 +380,8 @@ static int emulator_main(int argc, char *argv[], char **envp)
     LOG_INFO("Start emulator...\n");
     print_options_info();
 
+    init_emul_state();
+
     LOG_INFO("qemu main start...\n");
     qemu_main(_qemu_argc, _qemu_argv, envp);