shm: fix shared memory leak 47/10847/1
authormunkyu.im <munkyu.im@samsung.com>
Mon, 14 Oct 2013 07:06:13 +0000 (16:06 +0900)
committermunkyu.im <munkyu.im@samsung.com>
Mon, 14 Oct 2013 07:08:07 +0000 (16:08 +0900)
There was a shared memory leak when exit emulator.
So clear it.

Change-Id: I31f0f030f5e0f88a054547e4df064705898921c1
Signed-off-by: munkyu.im <munkyu.im@samsung.com>
tizen/src/emulator.c
tizen/src/osutil-darwin.c

index 826cb4ccb7567b87f36bd282068f886a44a75a52..7850cd99255d1d1f6b1b935e2e2d1459191d300a 100644 (file)
@@ -57,7 +57,7 @@
 #ifdef CONFIG_SDL
 #include <SDL.h>
 #endif
-#ifdef CONFIG_LINUX
+#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
 #include <sys/ipc.h>
 #include <sys/shm.h>
 extern int g_shmid;
@@ -116,8 +116,7 @@ void exit_emulator(void)
     shutdown_guest_server();
     stop_ecs();
 
-#ifdef CONFIG_LINUX
-    /* clean up the vm lock memory by munkyu */
+#if defined(CONFIG_LINUX) || defined(CONFIG_DARWIN)
     if (shmctl(g_shmid, IPC_RMID, 0) == -1) {
         ERR("shmctl failed\n");
         perror("emulator.c: ");
index c5225fa64bf2f8c625a3f573bd131a7301c7d336..f39ba632ee72ee29bec76918303ac65ec4efa2a9 100644 (file)
@@ -52,6 +52,7 @@
 
 MULTI_DEBUG_CHANNEL(qemu, osutil);
 
+int g_shmid;
 extern char tizen_target_img_path[];
 CFDictionaryRef proxySettings;
 
@@ -84,24 +85,23 @@ void check_vm_lock_os(void)
 
 void make_vm_lock_os(void)
 {
-    int shmid;
     char *shared_memory;
     int base_port;
     base_port = get_emul_vm_base_port();
-    shmid = shmget((key_t)base_port, MAXLEN, 0666|IPC_CREAT);
-    if (shmid == -1) {
+    g_shmid = shmget((key_t)base_port, MAXLEN, 0666|IPC_CREAT);
+    if (g_shmid == -1) {
         ERR("shmget failed\n");
         perror("osutil-darwin: ");
         return;
     }
 
-    shared_memory = shmat(shmid, (char *)0x00, 0);
+    shared_memory = shmat(g_shmid, (char *)0x00, 0);
     if (shared_memory == (void *)-1) {
         ERR("shmat failed\n");
         perror("osutil-darwin: ");
         return;
     }
-    sprintf(shared_memory, "%s", tizen_target_img_path);
+    g_sprintf(shared_memory, "%s", tizen_target_img_path);
     INFO("shared memory key: %d, value: %s\n", base_port, (char *)shared_memory);
     
     if (shmdt(shared_memory) == -1) {