From: Hwankyu Jhun Date: Tue, 27 Sep 2022 06:03:42 +0000 (+0000) Subject: Fix static anlaysis issues X-Git-Tag: accepted/tizen/unified/20220928.144445~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=142004a960943efa2dd32159543d187ba3f1c860;p=platform%2Fcore%2Fappfw%2Fevent-system.git Fix static anlaysis issues The following issues are fixed: - NULL_RETURNS - AUTO_CAUSES_COPY Change-Id: Id7244305e0762f6b532dff6ea792a68740e49872 Signed-off-by: Hwankyu Jhun --- diff --git a/src/esd_cion/cion_ondemand_server.cc b/src/esd_cion/cion_ondemand_server.cc index 13f9923..a7c267b 100644 --- a/src/esd_cion/cion_ondemand_server.cc +++ b/src/esd_cion/cion_ondemand_server.cc @@ -290,7 +290,7 @@ void CionOndemandServer::LoadOndemandServiceList() { void CionOndemandServer::AddOndemandServiceList(std::string service_name, std::string appid, std::string display_name) { - for (auto peer : ondemand_peer_list_) { + for (auto const& peer : ondemand_peer_list_) { if (peer->GetServiceName() == service_name && peer->GetAppID() == appid) { _W("%s is already exist", appid.c_str()); @@ -330,7 +330,7 @@ void CionOndemandServer::AddOndemandServiceList(std::string service_name, void CionOndemandServer::RemoveOndemandServiceList(std::string service_name, std::string appid) { for (auto peer = ondemand_peer_list_.begin(); - peer != ondemand_peer_list_.end(); peer++) { + peer != ondemand_peer_list_.end(); peer++) { if (peer->get()->GetServiceName() == service_name && peer->get()->GetAppID() == appid) { ondemand_peer_list_.erase(peer); diff --git a/src/esd_cion/cion_ondemand_server.h b/src/esd_cion/cion_ondemand_server.h index b3852d0..3f7ed16 100644 --- a/src/esd_cion/cion_ondemand_server.h +++ b/src/esd_cion/cion_ondemand_server.h @@ -59,4 +59,4 @@ class CionOndemandServer : public cion::channel::ServerChannel { std::list> ondemand_peer_list_; }; -#endif /* EVENTSYSTEM_DAEMON_CION_ONDEMAND_SERVER_H_ */ \ No newline at end of file +#endif /* EVENTSYSTEM_DAEMON_CION_ONDEMAND_SERVER_H_ */ diff --git a/src/esd_cion/esd_cion_db.c b/src/esd_cion/esd_cion_db.c index 61b7b5b..f6689f4 100644 --- a/src/esd_cion/esd_cion_db.c +++ b/src/esd_cion/esd_cion_db.c @@ -431,12 +431,79 @@ out: return ret; } +static void __cion_service_info_destroy(cion_service_info_s *info) +{ + if (info == NULL) + return; + + free(info->service_name); + free(info->appid); + free(info->display_name); + free(info); +} + +static cion_service_info_s *__cion_service_info_create(sqlite3_stmt *stmt) +{ + cion_service_info_s *info; + const char* value; + int index = 0; + + info = calloc(1, sizeof(cion_service_info_s)); + if (info == NULL) { + _E("malloc() is failed"); + return NULL; + } + + value = (const char *)sqlite3_column_text(stmt, index++); + if (value == NULL) { + _E("sqlite3_column_text() is failed. index: %d", index - 1); + __cion_service_info_destroy(info); + return NULL; + } + + info->service_name = strdup(value); + if (info->service_name == NULL) { + _E("strdup() is failed"); + __cion_service_info_destroy(info); + return NULL; + } + + value = (const char *)sqlite3_column_text(stmt, index++); + if (value == NULL) { + _E("sqlite3_column_text() is failed. index: %d", index - 1); + __cion_service_info_destroy(info); + return NULL; + } + + info->appid = strdup(value); + if (info->appid == NULL) { + _E("strdup() is failed"); + __cion_service_info_destroy(info); + return NULL; + } + + value = (const char *)sqlite3_column_text(stmt, index++); + if (value != NULL) + info->display_name = strdup(value); + else + info->display_name = strdup(""); + + if (info->display_name == NULL) { + _E("strdup() is failed"); + __cion_service_info_destroy(info); + return NULL; + } + + return info; +} + int esd_cion_get_enabled_service_list(GList **list) { int ret = -1; sqlite3 *db; char *query = NULL; sqlite3_stmt *stmt = NULL; + cion_service_info_s *cion_info; db = esd_cion_db_open(); if (!db) { @@ -453,19 +520,16 @@ int esd_cion_get_enabled_service_list(GList **list) if (ret != SQLITE_OK) goto out; - while(sqlite3_step(stmt) == SQLITE_ROW) { - cion_service_info_s *cion_info = malloc(sizeof(cion_service_info_s)); - cion_info->service_name = strdup((char*)sqlite3_column_text(stmt, 0)); - cion_info->appid = strdup((char*)sqlite3_column_text(stmt, 1)); + while (sqlite3_step(stmt) == SQLITE_ROW) { + cion_info = __cion_service_info_create(stmt); + if (cion_info == NULL) { + ret = -1; + goto out; + } - char *display_name = (char*)sqlite3_column_text(stmt, 2); - if (display_name) - cion_info->display_name = strdup(display_name); - else - cion_info->display_name = strdup(""); _D("get list : [%s:%s:%s]", - cion_info->service_name, cion_info->appid, cion_info->display_name); - + cion_info->service_name, cion_info->appid, + cion_info->display_name); *list = g_list_append(*list, cion_info); }