From 32912a5560311cebccebfacf46ef00e23afd240a Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 25 Jan 2018 17:14:40 +0900 Subject: [PATCH] Fix fd leak csr_cs_context_destroy should be invoked. Change-Id: I8a57241a28c9bbf4024e3904197409c7e27fb11d Signed-off-by: Sangyoon Jang --- src/pkgmgr-server.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/pkgmgr-server.c b/src/pkgmgr-server.c index e7559f7..0ac356f 100644 --- a/src/pkgmgr-server.c +++ b/src/pkgmgr-server.c @@ -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) -- 2.7.4