Fix Coverity issues 74/297274/9 accepted/tizen/8.0/unified/20231005.093427 accepted/tizen/unified/20230821.103313 tizen_8.0_m2_release
authorJaechul Lee <jcsing.lee@samsung.com>
Wed, 16 Aug 2023 06:36:44 +0000 (15:36 +0900)
committerJaechul Lee <jcsing.lee@samsung.com>
Fri, 18 Aug 2023 04:55:20 +0000 (13:55 +0900)
[Version] 0.0.12
[Issue Type] Coverity(REVERSE_INULL, FORWARD_NULL)

Change-Id: Iec9afdc9ad2870d20b79e0c5d67051939faa31ea
Signed-off-by: Jaechul Lee <jcsing.lee@samsung.com>
packaging/libaudio-effect.spec
src/audio_effect_interface.c

index ec9e63a291c85a5d976abf5b63202e8f59b6d7ac..3a3a57ed04de874f94bc7d18051742dea095c6cd 100644 (file)
@@ -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
index c242f10f8aa7102be26fe3edfa3cdc2cdb82b946..e507a70ae392a427fb2b0e96da9ea0d4a7d3d4c9 100644 (file)
@@ -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]));
 }