From: Jaechul Lee Date: Wed, 16 Aug 2023 06:36:44 +0000 (+0900) Subject: Fix Coverity issues X-Git-Tag: accepted/tizen/unified/20230821.103313^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=40aebd6b1a6e15ef126d6303360f34e563ec2a11;p=platform%2Fcore%2Fmultimedia%2Flibaudio-effect.git Fix Coverity issues [Version] 0.0.12 [Issue Type] Coverity(REVERSE_INULL, FORWARD_NULL) Change-Id: Iec9afdc9ad2870d20b79e0c5d67051939faa31ea Signed-off-by: Jaechul Lee --- diff --git a/packaging/libaudio-effect.spec b/packaging/libaudio-effect.spec index ec9e63a..3a3a57e 100644 --- a/packaging/libaudio-effect.spec +++ b/packaging/libaudio-effect.spec @@ -1,6 +1,6 @@ Name: libaudio-effect Summary: audio effect library -Version: 0.0.11 +Version: 0.0.12 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/src/audio_effect_interface.c b/src/audio_effect_interface.c index c242f10..e507a70 100644 --- a/src/audio_effect_interface.c +++ b/src/audio_effect_interface.c @@ -45,11 +45,7 @@ static const char *effect_path_list[] = { static_assert(sizeof(effect_path_list) / sizeof(char *) == AUDIO_EFFECT_METHOD_MAX); -static struct plugin_list { - void *handle; - int refcnt; - audio_effect_plugin_info_s *plugin_info; -} plugin_list[AUDIO_EFFECT_METHOD_MAX]; +static void *dl_handles[AUDIO_EFFECT_METHOD_MAX]; static const char *get_plugin_name(const char *name) { @@ -64,19 +60,21 @@ audio_effect_interface_s *audio_effect_interface_new(audio_effect_method_e metho { audio_effect_plugin_info_s *plugin_info; entry_point_t entry_point; - void *handle = NULL; + void *handle; assert(method < AUDIO_EFFECT_METHOD_MAX); - LOG_INFO("Trying to create the plugin %s. plugin_info(%p), refcnt(%d)", - get_plugin_name(effect_path_list[method]), plugin_list[method].plugin_info, plugin_list[method].refcnt); + LOG_INFO("Trying to create the plugin. method(%s)", get_plugin_name(effect_path_list[method])); + + if (dl_handles[method]) { + LOG_ERROR("Failed to load plugin. It's already loaded. method(%s)", get_plugin_name(effect_path_list[method])); + return NULL; + } - if (!plugin_list[method].plugin_info && plugin_list[method].refcnt == 0) { - handle = dlopen(effect_path_list[method], RTLD_LAZY); - if (!handle) { - LOG_ERROR("Failed to open handle. path(%s) dlerror(%s)", get_plugin_name(effect_path_list[method]), dlerror()); - return NULL; - } + handle = dlopen(effect_path_list[method], RTLD_LAZY); + if (!handle) { + LOG_ERROR("Failed to open handle. path(%s) dlerror(%s)", get_plugin_name(effect_path_list[method]), dlerror()); + return NULL; } entry_point = dlsym(handle, PLUGIN_ENTRY_POINT_STRING); @@ -116,20 +114,14 @@ audio_effect_interface_s *audio_effect_interface_new(audio_effect_method_e metho if (plugin_info->constraint.frames != 0 && plugin_info->constraint.frames != frames) LOG_WARN("This plugin uses fixed frames size. Check frames size with audio_effect_get_process_framesize api"); - plugin_list[method].handle = handle; - /* TODO handle lock */ - plugin_list[method].refcnt += 1; + dl_handles[method] = handle; - LOG_INFO("plugin(%s) was created successfully. handle(%p) ref(%d)", - get_plugin_name(effect_path_list[method]), plugin_list[method].handle, plugin_list[method].refcnt); + LOG_INFO("plugin(%s) was created successfully. handle(%p)", get_plugin_name(effect_path_list[method]), dl_handles[method]); return &plugin_info->interface; fail: - if (handle) - dlclose(handle); - - plugin_list[method].plugin_info = NULL; + dlclose(handle); return NULL; } @@ -137,24 +129,20 @@ fail: void audio_effect_interface_free(audio_effect_interface_s *intf) { audio_effect_method_e method; + int ret; assert(intf); + assert(dl_handles[intf->method]); + assert(intf->method < AUDIO_EFFECT_METHOD_MAX); method = intf->method; - plugin_list[method].refcnt -= 1; + LOG_INFO("unloading the plugin. (%s). handle(%p)", get_plugin_name(effect_path_list[method]), dl_handles[method]); - if (plugin_list[method].refcnt == 0) { - int ret; - LOG_INFO("unloading the plugin. (%s). handle(%p)", - get_plugin_name(effect_path_list[method]), plugin_list[method].handle); - - if ((ret = dlclose(plugin_list[method].handle)) != 0) - LOG_ERROR("Failed to close plugin. ret(%d), dlerror(%s)", ret, dlerror()); - } + if ((ret = dlclose(dl_handles[method])) != 0) + LOG_ERROR("Failed to close plugin. ret(%d), dlerror(%s)", ret, dlerror()); - plugin_list[method].handle = NULL; - plugin_list[method].plugin_info = NULL; + dl_handles[method] = NULL; LOG_INFO("unloaded the plugin. (%s)", get_plugin_name(effect_path_list[method])); }