Fix static analysis issues 02/263102/3
authorSukhyungKang <shine.kang@samsung.com>
Thu, 26 Aug 2021 06:59:52 +0000 (15:59 +0900)
committerjusung <jusung07.son@samsung.com>
Thu, 26 Aug 2021 07:57:44 +0000 (16:57 +0900)
 - NO_CATCH
 - UNINIT.LOCAL_VAR.EX
 - MEMORY_LEAK.EX
 - BAD_SIZEOF
 - FORWARD_NULL
 - USE_AFTER_FREE

Change-Id: Icc2afb3ca9ebb431b278dfbd7296d6ead1683a66
Signed-off-by: SukhyungKang <shine.kang@samsung.com>
Signed-off-by: jusung <jusung07.son@samsung.com>
src/esd_cion/cion_ondemand_server.cc
src/esd_cion/esd_cion.cc
src/esd_cion/esd_cion_db.c
src/esd_main.c

index 0d5965e..2493ac3 100644 (file)
@@ -322,6 +322,8 @@ void CionOndemandServer::AddOndemandServiceList(std::string service_name,
       std::make_shared<CionPeerInfo>(service_name, parcel.GetRaw().data(),
       parcel.GetRaw().size());
   ondemand_peer_list_.emplace_back(pi);
+  free(uuid);
+
   _D("[%s:%s] is added to list", appid.c_str(), service_name.c_str());
 }
 
index 8ee6485..a91b95c 100644 (file)
@@ -28,13 +28,12 @@ int _esd_cion_init() {
   try {
     esd_cion_server =
         std::make_shared<CionOndemandServer>("__CION_INTERNAL_DAEMON__", "");
+    esd_cion_server->Listen();
   } catch (const cion::Exception& e) {
     _D("cion_init failed : %s", e.what());
     return -1;
   }
 
-  esd_cion_server->Listen();
-
   _D("cion_init done");
 
   return 0;
index 1a99dc0..61b7b5b 100644 (file)
@@ -160,7 +160,7 @@ static const char *__esd_cion_generate_uuid() {
 static int __esd_cion_get_uuid(sqlite3 *db, const char *appid, char **uuid) {
        int ret = -1;
        char *query;
-       sqlite3_stmt *stmt;
+       sqlite3_stmt *stmt = NULL;
 
        query = sqlite3_mprintf("SELECT uuid FROM cion_uuid "
                        "WHERE appid = %Q", appid);
@@ -187,7 +187,7 @@ out:
 static int __esd_cion_set_uuid(sqlite3 *db, const char *appid, const char *uuid) {
        int ret = -1;
        char *query;
-       sqlite3_stmt *stmt;
+       sqlite3_stmt *stmt = NULL;
 
        query = sqlite3_mprintf("INSERT INTO cion_uuid (appid, uuid) "
                        "VALUES (%Q, %Q) ", appid, uuid);
@@ -242,7 +242,7 @@ int esd_cion_set_display_name(const char *appid, const char *service_name,
        sqlite3 *db;
        char *query = NULL;
        sqlite3_stmt *stmt = NULL;
-       char *_uuid;
+       char *_uuid = NULL;
 
        db = esd_cion_db_open();
        if (!db) {
@@ -250,16 +250,11 @@ int esd_cion_set_display_name(const char *appid, const char *service_name,
                return -1;
        }
 
-       if (__esd_cion_get_uuid(db, appid, &_uuid) == 0) {
-               free(_uuid);
-       } else {
+       if (__esd_cion_get_uuid(db, appid, &_uuid) != 0) {
                _uuid = (char*)__esd_cion_generate_uuid();
                ret = __esd_cion_set_uuid(db, appid, _uuid);
-               if (ret != 0) {
-                       free(_uuid);
+               if (ret != 0)
                        goto out;
-               }
-               _E("set uuid generate");
        }
 
        query = sqlite3_mprintf("INSERT INTO cion_display_name "
@@ -282,6 +277,7 @@ int esd_cion_set_display_name(const char *appid, const char *service_name,
                ret = 0;
 
 out:
+       free(_uuid);
        sqlite3_free(query);
        sqlite3_finalize(stmt);
        esd_cion_db_close(&db);
@@ -341,7 +337,7 @@ int esd_cion_set_enabled(const char *appid, const char *service_name,
        int ret = -1;
        sqlite3 *db;
        char *query = NULL;
-       const char *display_name = NULL;
+       const char *display_name = "";
        sqlite3_stmt *stmt = NULL;
        sqlite3_stmt *select_stmt = NULL;
 
@@ -361,6 +357,11 @@ int esd_cion_set_enabled(const char *appid, const char *service_name,
        if (ret != SQLITE_OK)
                goto out;
 
+       ret = sqlite3_step(stmt);
+       if (ret != SQLITE_OK && ret != SQLITE_DONE)
+               goto out;
+
+       sqlite3_free(query);
        query = sqlite3_mprintf("SELECT display_name FROM cion_display_name "
                        "WHERE appid = %Q AND service_name = %Q", appid, service_name);
        if (query == NULL)
@@ -370,10 +371,6 @@ int esd_cion_set_enabled(const char *appid, const char *service_name,
        if (ret != SQLITE_OK)
                goto out;
 
-       ret = sqlite3_step(stmt);
-       if (ret != SQLITE_OK && ret != SQLITE_DONE)
-               goto out;
-
        ret = sqlite3_step(select_stmt);
        if (ret == SQLITE_ROW) {
                ret = 0;
@@ -464,6 +461,8 @@ int esd_cion_get_enabled_service_list(GList **list)
                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);
 
index 69d5eb1..5a931ad 100644 (file)
@@ -1310,7 +1310,7 @@ static int __esd_get_appid_by_pid(int pid, char *app_id, int buf_size)
                if (fd < 0)
                        return ES_R_ERROR;
 
-               ret = read(fd, app_id, sizeof(app_id) - 1);
+               ret = read(fd, app_id, buf_size - 1);
                close(fd);
 
                if (ret <= 0)
@@ -2066,10 +2066,8 @@ static void __esd_on_bus_acquired(GDBusConnection *connection,
                        NULL,
                        NULL);
 
-       if (boot_id == 0) {
+       if (boot_id == 0)
                _E("g_dbus_connection_signal_subscribe() is failed.");
-               g_object_unref(connection);
-       }
 
        user_boot_id = g_dbus_connection_signal_subscribe(connection,
                        NULL,
@@ -2082,10 +2080,8 @@ static void __esd_on_bus_acquired(GDBusConnection *connection,
                        NULL,
                        NULL);
 
-       if (user_boot_id == 0) {
+       if (user_boot_id == 0)
                _E("g_dbus_connection_signal_subscribe() is failed.");
-               g_object_unref(connection);
-       }
 }
 
 static void __esd_on_name_acquired(GDBusConnection *connection,