Fix Prevent issue
authorTae-Jeong Lee <taejeong.lee@samsung.com>
Tue, 8 Oct 2013 09:17:05 +0000 (18:17 +0900)
committerHoseon LEE <hoseon46.lee@samsung.com>
Mon, 14 Oct 2013 11:35:27 +0000 (20:35 +0900)
[Issue#]   CID: 17523
[Problem]  Resource leak.
[Cause]    There was allocated memory resources that we intentionally keep it
           not to be released until its process terminates.
[Solution] Use atexit() to release resources properly.

Change-Id: I05658e633d9c7537731368a5e0ec27a76355bebe

src/wrt-launchpad-daemon/include/process_pool_launchpad_util.h

index 0026e2b..ce4cd97 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef __PROCESS_POOL_LAUNCHPAD_UTIL_H_
 #define __PROCESS_POOL_LAUNCHPAD_UTIL_H_
 
+#include <stdlib.h>
 #include <launchpad_util.h>
 #include <smack_labeling_support.h>
 
@@ -73,6 +74,16 @@ _static_ int __process_pool_prepare_exec(const char *pkg_name,
     return 0;
 }
 
+
+static bundle *_s_bundle = NULL;
+static void __at_exit_to_release_bundle()
+{
+    if (_s_bundle) {
+        bundle_free(_s_bundle);
+        _s_bundle = NULL;
+    }
+}
+
 _static_ void process_pool_launchpad_main_loop(app_pkt_t* pkt, char* out_app_path, int* out_argc, char ***out_argv)
 
 {
@@ -88,6 +99,12 @@ _static_ void process_pool_launchpad_main_loop(app_pkt_t* pkt, char* out_app_pat
         exit(-1);
     }
 
+    if (_s_bundle != NULL) {
+        bundle_free(_s_bundle);
+    }
+    _s_bundle = kb;
+    atexit(__at_exit_to_release_bundle);
+
     pkg_name = bundle_get_val(kb, AUL_K_PKG_NAME);
     SECURE_LOGD("pkg name : %s", pkg_name);
 
@@ -134,16 +151,9 @@ _static_ void process_pool_launchpad_main_loop(app_pkt_t* pkt, char* out_app_pat
         exit(-1);
     }
 
-
-#if 0 // intentional
     if (menu_info != NULL) {
         _free_app_info_from_db(menu_info);
     }
-
-    if (kb != NULL) {
-        bundle_free(kb);
-    }
-#endif
 }
 
-#endif // __PROCESS_POOL_LAUNCHPAD_UTIL_H_
\ No newline at end of file
+#endif // __PROCESS_POOL_LAUNCHPAD_UTIL_H_