From 59fd74515602853afce0082e2d6f9a95a6baaac7 Mon Sep 17 00:00:00 2001 From: Nishant Chaprana Date: Thu, 21 Nov 2019 19:34:41 +0530 Subject: [PATCH] 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 --- ua-daemon/src/pm/ua-cloud-plugin-handler.c | 1 + ua-daemon/src/pm/ua-plugin-manager.c | 6 +++++- ua-daemon/src/pm/ua-vendor-plugin-manager.c | 8 ++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) 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; -- 2.7.4