Fix _pkg_plugin_load_library() 89/100389/1
authorSangyoon Jang <s89.jang@samsung.com>
Mon, 28 Nov 2016 04:40:21 +0000 (13:40 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Mon, 28 Nov 2016 04:40:21 +0000 (13:40 +0900)
Return before loading the library if the library already loaded.

Change-Id: Ia97fca4a27a6e76169dd97b51741994a47ac02a7
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
client/src/pkgmgr_client_internal.c

index c7ecacf..d2fbc6a 100644 (file)
@@ -329,11 +329,18 @@ pkg_plugin_set *_pkg_plugin_load_library(const char *pkg_type,
        int i;
        bool (*on_load)(pkg_plugin_set *plugin);
 
-       if (library_path == NULL) {
-               ERR("pkg library path = [%s]", library_path);
+       if (library_path == NULL || pkg_type == NULL) {
+               ERR("invalid parameter");
                return NULL;
        }
 
+       for (i = 0; plugin_set_list[i]; i++) {
+               if (strcmp(plugin_set_list[i]->pkg_type, pkg_type) == 0) {
+                       DBG("already loaded [%s]", library_path);
+                       return plugin_set_list[i];
+               }
+       }
+
        if ((library_handle = dlopen(library_path, RTLD_LAZY)) == NULL) {
                ERR("dlopen is failed library_path[%s]", library_path);
                return NULL;
@@ -346,13 +353,6 @@ pkg_plugin_set *_pkg_plugin_load_library(const char *pkg_type,
                return NULL;
        }
 
-       for (i = 0; plugin_set_list[i]; i++) {
-               if (strcmp(plugin_set_list[i]->pkg_type, pkg_type) == 0) {
-                       DBG("already loaded [%s]", library_path);
-                       return plugin_set_list[i];
-               }
-       }
-
        plugin_set_list[i] = (pkg_plugin_set *)calloc(1, sizeof(pkg_plugin_set));
        if (plugin_set_list[i] == NULL) {
                ERR("malloc of the plugin_set_list element is failed");