From: Nishant Chaprana Date: Thu, 21 Nov 2019 14:04:41 +0000 (+0530) Subject: Fix handle leak when loading plugins X-Git-Tag: accepted/tizen/unified/20191125.135542~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=59fd74515602853afce0082e2d6f9a95a6baaac7;p=platform%2Fcore%2Fconnectivity%2Fua-manager.git Fix handle leak when loading plugins - Problem: dlopen() returned handle was leaking when loading plugins in loop. - Cause: dlcose() not called when plugin add operation fails. - Solution: Call dlcose() when plugin add operation fails. Change-Id: Id3c1d9a42fb2ef8b9b9e5b64393c40f6e771d9fc Signed-off-by: Nishant Chaprana --- diff --git a/ua-daemon/src/pm/ua-cloud-plugin-handler.c b/ua-daemon/src/pm/ua-cloud-plugin-handler.c index 13fe6d9..f1de902 100644 --- a/ua-daemon/src/pm/ua-cloud-plugin-handler.c +++ b/ua-daemon/src/pm/ua-cloud-plugin-handler.c @@ -313,6 +313,7 @@ static int __load_cloud_plugin(void) if (FALSE == __add_cloud_plugin(handle, module)) { UAM_WARN("__add_cloud_plugin failed"); + dlclose(handle); continue; } diff --git a/ua-daemon/src/pm/ua-plugin-manager.c b/ua-daemon/src/pm/ua-plugin-manager.c index 3f567fd..c5ae741 100644 --- a/ua-daemon/src/pm/ua-plugin-manager.c +++ b/ua-daemon/src/pm/ua-plugin-manager.c @@ -126,7 +126,11 @@ static int __load_plugin(const char *path, const char *name, const char *symbol) return UAM_ERROR_INTERNAL; } - retv_if(FALSE == __add_plugin(handle, module), UAM_ERROR_INTERNAL); + if (FALSE == __add_plugin(handle, module)) { + UAM_ERR("Can't add plugin module"); + dlclose(handle); + return UAM_ERROR_INTERNAL; + } FUNC_EXIT; return UAM_ERROR_NONE; diff --git a/ua-daemon/src/pm/ua-vendor-plugin-manager.c b/ua-daemon/src/pm/ua-vendor-plugin-manager.c index f60a560..22237de 100644 --- a/ua-daemon/src/pm/ua-vendor-plugin-manager.c +++ b/ua-daemon/src/pm/ua-vendor-plugin-manager.c @@ -126,7 +126,7 @@ static int __load_vendor_plugin(const char *path, const char *name, const char * module = (uav_module_t *)dlsym(handle, symbol); if (module == NULL) { - UAM_ERR("Can't load power plugin module: %s", dlerror()); + UAM_ERR("Can't load plugin module: %s", dlerror()); dlclose(handle); return UAM_ERROR_INTERNAL; } @@ -137,7 +137,11 @@ static int __load_vendor_plugin(const char *path, const char *name, const char * return UAM_ERROR_INVALID_PARAMETER; } - retv_if(FALSE == __add_vendor_plugin(handle, module), UAM_ERROR_INTERNAL); + if (FALSE == __add_vendor_plugin(handle, module)) { + UAM_ERR("Can't add plugin module: %s", dlerror()); + dlclose(handle); + return UAM_ERROR_INTERNAL; + } FUNC_EXIT; return UAM_ERROR_NONE;