Fix fd leak
[platform/core/appfw/pkgmgr-server.git] / 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)