From: YoungHun Kim Date: Fri, 16 Aug 2024 01:39:39 +0000 (+0900) Subject: Fix the svace and coverity issue X-Git-Tag: accepted/tizen/unified/20240821.081505^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3a95daf1c41b81679637aeb66166975a9e72a683;p=platform%2Fcore%2Fmultimedia%2Fresource-manager.git Fix the svace and coverity issue - UNINIT.CTOR.MANY DEREF_OF_NULL.RET.ALLOC etc Change-Id: I7c5149a98f3bc73fc36cb218f006015d7d7a0e54 --- diff --git a/include/RMShm.h b/include/RMShm.h index bc21e7d..eb38d72 100644 --- a/include/RMShm.h +++ b/include/RMShm.h @@ -170,9 +170,9 @@ protected: void SetDeviceID(const int device_id) { device_id_ = device_id; } private: - int device_id_; - int state_; - int player_id_; + int device_id_ {}; + int state_ {}; + int player_id_ {}; }; /** @@ -270,8 +270,8 @@ public: int GetVirtualID(void) { return virtual_id_; } private: - int zone_id_; - int virtual_id_; + int zone_id_ {}; + int virtual_id_ {}; }; #ifdef __cplusplus diff --git a/include_internal/RMShmCache.h b/include_internal/RMShmCache.h index 0d57ad9..f8c9a12 100644 --- a/include_internal/RMShmCache.h +++ b/include_internal/RMShmCache.h @@ -55,7 +55,7 @@ private: bool Init(void); - bool ready_; + bool ready_ {}; std::mutex init_mutex_; shared::segment *shm_segment_; diff --git a/packaging/resource-manager.spec b/packaging/resource-manager.spec index 6f0df4c..ec83557 100644 --- a/packaging/resource-manager.spec +++ b/packaging/resource-manager.spec @@ -1,7 +1,7 @@ Name: resource-manager Summary: Resource manager Version: 0.1 -Release: 1 +Release: 2 Group: Multimedia/Libraries License: Apache-2.0 Source0: %{name}-%{version}.tar.gz diff --git a/src/RMShmCache.cpp b/src/RMShmCache.cpp index 36cb180..ba3621f 100644 --- a/src/RMShmCache.cpp +++ b/src/RMShmCache.cpp @@ -27,27 +27,27 @@ static std::mutex instance_mutex_; RMShmCache *RMShmCache::GetInstance(void) { - if (instance_ == nullptr) { - std::lock_guard guard(instance_mutex_); - if (instance_ == nullptr) { - instance_ = new RMShmCache(); - } - } + std::lock_guard guard(instance_mutex_); + + if (instance_ == nullptr) + instance_ = new RMShmCache(); + return instance_; } RMShmCache::RMShmCache(): ready_(false) { - Init(); + if (!Init()) + RM_ERR("Init is failed"); } bool RMShmCache::Init(void) { + std::lock_guard guard(init_mutex_); + if (ready_) return true; - std::lock_guard guard(init_mutex_); - try { shm_segment_ = new shared::segment(boost::interprocess::open_read_only, "shm_rm"); players_ = shm_segment_->find>("players").first; @@ -60,6 +60,7 @@ bool RMShmCache::Init(void) } ready_ = true; + return true; } @@ -173,6 +174,11 @@ int RMShmCache::FindPlayersUsingAudioMainOut(rm_resource_list_h *list) }; rm_resource_list *result = (rm_resource_list*) calloc(1, sizeof(rm_resource_list)); + if (!result) { + RM_ERR("rm_resource_list calloc failed"); + return RM_ERROR; + } + result->n_rsc = 0; for (unsigned int i = 0; i < ARRAY_SIZE(audio_main_out_devices); i++) { @@ -183,6 +189,9 @@ int RMShmCache::FindPlayersUsingAudioMainOut(rm_resource_list_h *list) continue; rm_resource *resource = (rm_resource*) calloc(1, sizeof(rm_resource)); + if (!resource) + continue; + resource->id = audio_main_out_devices[i]; resource->state = RM_RSC_STATE_EXCLUSIVE; resource->consumer_id = it->second.GetPlayerID(); diff --git a/src/rm_api.cpp b/src/rm_api.cpp index b077301..fbf0c6e 100644 --- a/src/rm_api.cpp +++ b/src/rm_api.cpp @@ -171,7 +171,7 @@ int rm_allocate_resources(int handle, const rm_category_request_s *requests, rm_ RM_INFO("Request for Allocation handle[%d] / pid[%d] / requested #[%d]", handle, getpid(), requests->request_num); - for (idx=0; idx < requests->request_num; idx++) + for (idx = 0; idx < requests->request_num; idx++) RM_INFO("(%d) CatID[%d-%s] / CatOpt[%d]", idx + 1, requests->category_id[idx], rm_convert_category_enum_to_string(requests->category_id[idx]), requests->category_option[idx]); diff --git a/src/rm_callback.cpp b/src/rm_callback.cpp index 8bee3c2..75a2cf5 100644 --- a/src/rm_callback.cpp +++ b/src/rm_callback.cpp @@ -27,8 +27,7 @@ #include #include #include - -#include +#include #include #include @@ -87,7 +86,7 @@ static gpointer rm_run_loop(gpointer data) if (main_loop != NULL) g_main_loop_run(main_loop); - RM_INFO("RM client thread finished\n"); + RM_INFO("RM client thread finished"); return NULL; } @@ -111,12 +110,14 @@ int _create_event_loop(void) // LCOV_EXCL_STOP } - return RM_OK; + RM_INFO("RM_OK"); + return RM_OK; } int _create_cb_root_dir(void) { + rm_return_code_e ret = RM_OK; const char *cb_dir_path = "/run/rsc_mgr"; mode_t pmask; @@ -129,15 +130,21 @@ int _create_cb_root_dir(void) mode_t dir_mode = 0666 | 0111; pmask = umask(0); - if (mkdir(cb_dir_path, dir_mode) !=0) { + if (mkdir(cb_dir_path, dir_mode) != 0) { RM_ERR("failed to create cb directory (%d)", errno); - umask(pmask); - return RM_ERROR; + ret = RM_ERROR; + goto exit; } - chmod(cb_dir_path, dir_mode); + + if (chmod(cb_dir_path, dir_mode) == -1) { + RM_ERR("failed to create cb directory (%d)", errno); + ret = RM_ERROR; + } + +exit: umask(pmask); - return RM_OK; + return ret; // LCOV_EXCL_STOP } @@ -155,7 +162,7 @@ int _create_FIFO_s2c(int pid, int cid) pmask = umask(0); - if (mknod(cb_path_s2c, S_IFIFO|0666, 0)) { + if (mknod(cb_path_s2c, S_IFIFO | 0666, 0)) { RM_ERR("failed to create cb for S2C(%s)-(%d)", cb_path_s2c, errno); umask(pmask); return RM_ERROR; @@ -386,7 +393,7 @@ int rm_init_cb(int cid, rm_resource_cb cb, void *data) snprintf(cb_path_s2c, 256, "/run/rsc_mgr/%d.%d.s2c.cb", pid, cid); if ((fd = open(cb_path_s2c, O_RDWR|O_NONBLOCK)) < 0) { - RM_ERR("open error (%s), errno(%d)\n", cb_path_s2c, errno); + RM_ERR("open error (%s), errno(%d)", cb_path_s2c, errno); pthread_mutex_unlock(&rm_cb_mutex); return RM_ERROR; } diff --git a/ut/testcase/TCCallbackListener.cpp b/ut/testcase/TCCallbackListener.cpp index 81a6703..01729fa 100644 --- a/ut/testcase/TCCallbackListener.cpp +++ b/ut/testcase/TCCallbackListener.cpp @@ -43,7 +43,6 @@ void TCCallbackListener::ScalerStateChangeCb(rm_resource_list_h scalers, void *d TCCallbackListener::TCCallbackListener() { - m_n_notification = 0; } TCCallbackListener::~TCCallbackListener() diff --git a/ut/testcase/TCCallbackListener.h b/ut/testcase/TCCallbackListener.h index 37abd41..bcbe424 100644 --- a/ut/testcase/TCCallbackListener.h +++ b/ut/testcase/TCCallbackListener.h @@ -39,7 +39,7 @@ public: private: std::map m_scalers; - int m_n_notification; + int m_n_notification {}; }; #endif //__TC_CALLBACK_LISTENER_H__ diff --git a/ut/testcase/TCPlayer.cpp b/ut/testcase/TCPlayer.cpp index e7c9788..46b953f 100644 --- a/ut/testcase/TCPlayer.cpp +++ b/ut/testcase/TCPlayer.cpp @@ -25,12 +25,6 @@ TCPlayer::TCPlayer() { - m_handle = 0; - m_allocated_rsc_index = 0; - m_rsc_index = 0; - m_query_index = 0; - m_n_conflict = 0; - m_n_conflicted_rsc = 0; } TCPlayer::~TCPlayer() diff --git a/ut/testcase/TCPlayer.h b/ut/testcase/TCPlayer.h index 1cc1dfa..63d3327 100644 --- a/ut/testcase/TCPlayer.h +++ b/ut/testcase/TCPlayer.h @@ -71,12 +71,12 @@ private: std::map m_queries; std::string m_app_id; - int m_handle; - int m_rsc_index; - int m_query_index; - int m_allocated_rsc_index; - int m_n_conflict; - int m_n_conflicted_rsc; + int m_handle {}; + int m_rsc_index {}; + int m_query_index {}; + int m_allocated_rsc_index {}; + int m_n_conflict {}; + int m_n_conflicted_rsc {}; }; #endif //__TC_PLAYER_H__ diff --git a/ut/testcase/TCResource.cpp b/ut/testcase/TCResource.cpp index fc61df0..7bf824a 100644 --- a/ut/testcase/TCResource.cpp +++ b/ut/testcase/TCResource.cpp @@ -18,9 +18,6 @@ TCResource::TCResource(int category_id, int category_option, int state) { - m_category_id = category_id; - m_category_option = category_option; - m_state = state; } TCResource::~TCResource() diff --git a/ut/testcase/TCResource.h b/ut/testcase/TCResource.h index c3068b4..23f1953 100644 --- a/ut/testcase/TCResource.h +++ b/ut/testcase/TCResource.h @@ -20,7 +20,8 @@ class TCResource { public: - TCResource(int category_id, int category_option, int state); + TCResource(int category_id, int category_option, int state) + : m_category_id(category_id), m_category_option(category_option), m_state(state) {} ~TCResource(); int GetCategoryId(void) {return m_category_id;} @@ -28,9 +29,9 @@ public: int GetState(void) {return m_state;} private: - int m_category_id; - int m_category_option; - int m_state; + int m_category_id {}; + int m_category_option {}; + int m_state {}; }; #endif //__TC_RESOURCE_H__ diff --git a/ut/testcase/ut_main.cpp b/ut/testcase/ut_main.cpp index d8b7ad2..8a5d5d5 100644 --- a/ut/testcase/ut_main.cpp +++ b/ut/testcase/ut_main.cpp @@ -41,7 +41,7 @@ GMainContext *get_callback_thread_context(void) GTEST_API_ int main(int argc, char **argv) { - RM_TEST_MSG("Running main() from ut_main.cpp\n"); + RM_TEST_MSG("Running main() from ut_main.cpp"); //GMainContext *context = g_main_context_new(); g_main_loop = g_main_loop_new(NULL, FALSE); diff --git a/ut/testcase/ut_tc.cpp b/ut/testcase/ut_tc.cpp index b894c25..6152df2 100644 --- a/ut/testcase/ut_tc.cpp +++ b/ut/testcase/ut_tc.cpp @@ -105,9 +105,9 @@ rm_cb_result conflict_cb4(int handle, rm_callback_type event, rm_device_request_ return RM_CB_RESULT_OK; } -int flag1=0; -int flag2=0; -int endflag=0; +int flag1 = 0; +int flag2 = 0; +int endflag = 0; pthread_t t1,t2,t3; rm_cb_result cb1(int handle, rm_callback_type event, rm_device_request_s *info, void *data) { @@ -124,7 +124,7 @@ rm_cb_result cb2(int handle, rm_callback_type event, rm_device_request_s *info, void *thread_main1(void*) { - int handle=0; + int handle = 0; EXPECT_EQ(RM_OK,rm_register(cb1, NULL, &handle, NULL)); //alloc @@ -151,7 +151,7 @@ void *thread_main1(void*) } void *thread_main2(void*) { - int handle=0; + int handle = 0; while (true) { if (flag1) { EXPECT_EQ(RM_OK,rm_register(cb2, NULL, &handle, NULL)); @@ -167,7 +167,7 @@ void *thread_main2(void*) rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); memset((void*)allocated, 0, sizeof(rm_device_return_s)); EXPECT_EQ(RM_OK,rm_allocate_resources(handle, request, allocated)); - flag1=0; + flag1 = 0; } if (endflag) { @@ -180,7 +180,7 @@ void *thread_main2(void*) void *thread_main3(void*) { - int handle=0; + int handle = 0; while (true) { if (flag2) { EXPECT_EQ(RM_OK,rm_register(cb2, NULL, &handle, NULL)); @@ -1015,7 +1015,7 @@ TEST(ut_rm_api, rm_conflict_internal_msg_q) pthread_create(&t1,NULL,&thread_main1,(void*)1); pthread_create(&t2,NULL,&thread_main2,(void*)2); pthread_create(&t3,NULL,&thread_main3,(void*)3); - int status=0; + int status = 0; pthread_join(t1,(void**)&status); pthread_join(t2,(void**)&status); pthread_join(t3,(void**)&status);