Fix static analyzer issues
authorDaehyeon Jung <darrenh.jung@samsung.com>
Thu, 7 Mar 2019 04:57:27 +0000 (13:57 +0900)
committer정대현/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <darrenh.jung@samsung.com>
Fri, 8 Mar 2019 02:54:24 +0000 (11:54 +0900)
Change-Id: I53f79072c11409427a83c3ffd69646fd886044bc

src/common/dbus_service.cc
src/common/mdg_manager.cc
src/common/security_manager.cc
src/common/security_manager.h

index 28a908f709469689080021964ded81b5bd02b85c..d03203c418f25f23867e8cd0b0fffad20ff9063e 100644 (file)
@@ -102,12 +102,18 @@ SecurityManager::Credentials GetCredentials(
   ret = cynara_creds_gdbus_get_client(conn, sender, CLIENT_METHOD_DEFAULT,
           &client);
   if (ret != CYNARA_API_SUCCESS) {
+    if (user)
+      free(user);
     LOG(ERROR) << "cynara_creds_gdbus_get_client() failed: " << ret;
     return SecurityManager::Credentials();
   }
 
   ret = cynara_creds_gdbus_get_pid(conn, sender, &pid);
   if (ret != CYNARA_API_SUCCESS) {
+    if (user)
+      free(user);
+    if (client)
+      free(client);
     LOG(ERROR) << "cynara_creds_gdbus_get_pid() failed: " << ret;
     return SecurityManager::Credentials();
   }
@@ -115,7 +121,7 @@ SecurityManager::Credentials GetCredentials(
   return SecurityManager::Credentials(pid, client, user);
 }
 
-DBusService::DBusService() {
+DBusService::DBusService() : owner_id_(0), sid_(0) {
   node_info_ = g_dbus_node_info_new_for_xml(kDBusInstropectionXml, nullptr);
   if (node_info_) {
     owner_id_ = g_bus_own_name(G_BUS_TYPE_SYSTEM, kDBusServiceName,
@@ -275,8 +281,8 @@ bool DBusService::HandleSendFile(GVariant* params,
     GDBusMethodInvocation* invocation, const gchar* sender,
     GDBusConnection* connection) {
   LOG(INFO) << "HandleSendFile ";
-  gchar* device_id;
-  gchar* file_path;
+  const gchar* device_id;
+  const gchar* file_path;
   std::string file_path_str;
 
   g_variant_get(params, "(&s&s)", &device_id, &file_path);
@@ -300,7 +306,6 @@ bool DBusService::HandleSendFile(GVariant* params,
     LOG(ERROR) << "Failed to create credentials";
     return false;
   }
-
   if (!SecurityManager::CheckFilePermission(file_path_str, c)) {
     LOG(ERROR) << "File permission error: " << file_path_str;
     g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", -1));
@@ -313,12 +318,12 @@ bool DBusService::HandleSendFile(GVariant* params,
       reinterpret_cast<GDBusConnection*>(g_object_ref(connection)));
 
   file_map_.emplace(handle->file_path, handle);
-
   boost::optional<int> r =
       EventHandler().send_file_event(handle->device_id, handle->file_path);
 
   if (!r) {
     LOG(ERROR) << "Failed to send file";
+    g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", -1));
     return false;
   }
 
@@ -347,7 +352,7 @@ void DBusService::HandleMethodCall(GDBusConnection* connection,
     HandleSendRemoteAppControl(parameters, invocation);
     return;
   } else if (g_strcmp0("SendFile", method_name) == 0) {
-    r = HandleSendFile(parameters, invocation, sender, connection);
+    HandleSendFile(parameters, invocation, sender, connection);
     return;
   }
 
index 7bf88634a70830e929fb6b85b388eeec822bfc79..8e468a15e3e1c3a1c4360bb6e9fbe828a08a9047 100644 (file)
@@ -544,7 +544,7 @@ int MDGManager::SendData(const std::string& device_id, Command cmd,
   if (ret != MDG_ERROR_NONE)
     LOG(ERROR) << "Failed to send data: " << MDGErrorToString(ret);
 
-  delete buf;
+  delete[] buf;
 
   return msg_id;
 }
index ca2fbeec2f39225452a2148191539619187bf813..0b49e9190e701081ececabc39701e1907ae9007d 100644 (file)
 namespace capmgr {\r
 \r
 \r
-SecurityManager::Credentials::Credentials():  init_(false) {}\r
+SecurityManager::Credentials::Credentials():  init_(false), pid_(0),\r
+    user_(nullptr), smack_label_(nullptr) {}\r
 \r
 SecurityManager::Credentials::Credentials(int pid, const char* user,\r
     const char* smack_label) {\r
   pid_ = pid;\r
   init_ = false;\r
-  smack_label_ = strdup(smack_label);\r
-  if (!smack_label_) {\r
-    return;\r
-  }\r
-\r
   user_ = strdup(user);\r
   if (!user_) {\r
-    free(smack_label_);\r
     smack_label_ = nullptr;\r
     return;\r
   }\r
 \r
+  smack_label_ = strdup(smack_label);\r
+  if (!smack_label_) {\r
+    free(user_);\r
+    return;\r
+  }\r
   init_ = true;\r
 }\r
 \r
@@ -57,7 +57,7 @@ const char* SecurityManager::Credentials::GetUser() {
 }\r
 \r
 bool SecurityManager::CheckFilePermission(const std::string& file_path,\r
-    SecurityManager::Credentials c) {\r
+    const SecurityManager::Credentials& c) {\r
   char* real_file_path = nullptr;\r
   char* file_label = nullptr;\r
   int ret;\r
index 542bbc32d37e389814a989720ffb83e1f60025cf..f39a4e4d95bb1fe608736d828ee2ecf36c47fb3f 100644 (file)
@@ -30,7 +30,7 @@ class SecurityManager {
   };
 
   static bool CheckFilePermission(const std::string& file_path,
-            SecurityManager::Credentials c);
+            const SecurityManager::Credentials& c);
 };
 
 }  // namespace capmgr