Fix handle leak when loading plugins
authorNishant Chaprana <n.chaprana@samsung.com>
Thu, 21 Nov 2019 14:04:41 +0000 (19:34 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 21 Nov 2019 23:09:50 +0000 (08:09 +0900)
- 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 <n.chaprana@samsung.com>
ua-daemon/src/pm/ua-cloud-plugin-handler.c
ua-daemon/src/pm/ua-plugin-manager.c
ua-daemon/src/pm/ua-vendor-plugin-manager.c

index 13fe6d9..f1de902 100644 (file)
@@ -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;
                }
 
index 3f567fd..c5ae741 100644 (file)
@@ -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;
index f60a560..22237de 100644 (file)
@@ -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;