Fix fd leak 59/168259/2
authorSangyoon Jang <jeremy.jang@samsung.com>
Thu, 25 Jan 2018 08:14:40 +0000 (17:14 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Thu, 25 Jan 2018 08:19:09 +0000 (08:19 +0000)
csr_cs_context_destroy should be invoked.

Change-Id: I8a57241a28c9bbf4024e3904197409c7e27fb11d
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/pkgmgr-server.c

index e7559f7..0ac356f 100644 (file)
@@ -437,7 +437,7 @@ static int __check_csr(const char *path)
 {
        int ret;
        void *context;
-       void *malware;
+       void *malware = NULL;
        void *lib_handle;
        int (*_csr_cs_context_create)(void **handle);
        int (*_csr_cs_scan_file)(void *handle, const char *file_path, void **malware);
@@ -456,41 +456,34 @@ static int __check_csr(const char *path)
        if (!_csr_cs_context_create || !_csr_cs_scan_file ||
                        !_csr_cs_context_destroy) {
                ERR("Failed to load CSR symbols");
-               ret = -1;
-               goto catch;
+               dlclose(lib_handle);
+               return -1;
        }
 
        ret = _csr_cs_context_create(&context);
        if (ret != 0) {
                ERR("Failed to create context");
-               ret = -1;
-               goto catch;
+               dlclose(lib_handle);
+               return -1;
        }
 
        ret = _csr_cs_scan_file(context, path, &malware);
-       if (ret != 0) {
+       /* the csr engine may not exist */
+       if (ret != 0)
                DBG("CSR result[%d]", ret);
-               ret = 0;
-               goto catch;
-       }
 
        ret = _csr_cs_context_destroy(context);
-       if (ret != 0) {
+       if (ret != 0)
                ERR("Failed to destroy context");
-               ret = -1;
-               goto catch;
-       }
+
+       dlclose(lib_handle);
 
        if (malware != NULL) {
                ERR("CSR detected malware from [%s]", path);
-               ret = -1;
+               return -1;
+       } else {
+               return 0;
        }
-
-catch:
-       if (lib_handle)
-               dlclose(lib_handle);
-
-       return ret;
 }
 
 static int __kill_app(char *appid, uid_t uid)