From 08331ae017c52a1d1ceef5f34f38a90b60b210c9 Mon Sep 17 00:00:00 2001 From: Adam Michalski Date: Thu, 4 Jul 2024 11:47:59 +0200 Subject: [PATCH] Fix bugs in loading plugin set Fixes in the LoadPluginSet() function: - the naming scheme for backend libraries is "libTYPE.so", where TYPE is the backend type (e.g. for tpk it should load libtpk.so) - elements of the global plugin_set_list array should be allocated every time a new backend library is loaded as this behaviour is expected by the backend api: pkg_plugin_on_load() function expects its input parameter to be an already allocated memory area, otherwise it returns -1 and the LoadPluginSet() reports a failure: extern "C" int pkg_plugin_on_load(pkg_plugin_set* set) { if (set == nullptr) return -1; set->plugin_on_unload = PluginOnUnload; ... } Change-Id: I603030871a28f050f1d87ce572c102c3d0b5dc90 --- client/src/internal.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/src/internal.cc b/client/src/internal.cc index a02ec3a..9fb08a9 100644 --- a/client/src/internal.cc +++ b/client/src/internal.cc @@ -74,7 +74,7 @@ pkg_plugin_set* LoadPluginSet(const std::string& type) { } } - std::string lib_path = kPkgLibPath + type + ".so"; + std::string lib_path = kPkgLibPath + std::string("lib") + type + ".so"; void* handle = dlopen(lib_path.c_str(), RTLD_LAZY); if (!handle) { _E("failed to load library %s", lib_path.c_str()); @@ -90,6 +90,13 @@ pkg_plugin_set* LoadPluginSet(const std::string& type) { return nullptr; } + plugin_set_list[i] = reinterpret_cast(calloc(1, sizeof(pkg_plugin_set))); + if (plugin_set_list[i] == NULL) { + _E("malloc of the plugin_set_list element is failed"); + dlclose(handle); + return nullptr; + } + if (on_load(plugin_set_list[i]) != 0) { _E("pkg_plugin_on_load failed"); free(plugin_set_list[i]); -- 2.34.1