[messaging][bluetooth] Fixing Coverity issues 25/225225/2
authorPiotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/Samsung Electronics <p.kosko@samsung.com>
Tue, 18 Feb 2020 06:41:52 +0000 (07:41 +0100)
committerPiotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/Samsung Electronics <p.kosko@samsung.com>
Tue, 18 Feb 2020 09:32:38 +0000 (10:32 +0100)
Fixing below issues:
- messaging: 1098090, 1102306
- bluetooth: 1094938

[Verification]
bluetooth auto TCT: 100%
messaging sms TCT: 100%
messaging mms TCT: 100%

Change-Id: I12dc9d5cdc3ddd1e6c5c71f8fb92942bd1c63d96

src/bluetooth/bluetooth_adapter.cc
src/messaging/messaging_database_manager.cc
src/messaging/short_message_manager.cc

index 0da34d5..4e7456d 100644 (file)
@@ -1710,10 +1710,10 @@ void BluetoothAdapter::RemoveSocket(int socket) {
     LoggerW("Unknown connected socket: %d", socket);
     return;
   }
-
+  int id = *it;
   connected_sockets_.erase(it);
 
-  InvokeSocketOnCloseEvent(*it);
+  InvokeSocketOnCloseEvent(id);
 }
 
 void BluetoothAdapter::StoreSocketData(bt_socket_received_data_s* data) {
index dbdf03e..9efa3b3 100644 (file)
@@ -226,6 +226,8 @@ msg_error_t MessagingDatabaseManager::getTable(std::string sqlQuery, char*** res
 
   if (SQLITE_OK != err) {
     LoggerE("Getting table fail [%d] error_msg:%s querry was:%s", err, error_msg, sqlQuery.c_str());
+    sqlite3_free(error_msg);
+    error_msg = NULL;
     freeTable(results);
     return MSG_ERR_DB_GETTABLE;
   }
index 069a686..784b433 100644 (file)
@@ -123,13 +123,18 @@ PlatformResult ShortMsgManager::addDraftMessagePlatform(std::shared_ptr<Message>
   if (NULL == platform_msg) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Cannot prepare platform message");
   }
+  // releases platform_msg
+  std::unique_ptr<std::remove_pointer<msg_struct_t*>::type, decltype(&msg_release_struct)>
+      platform_msg_ptr(&platform_msg, &msg_release_struct);
 
   msg_struct_t send_opt = msg_create_struct(MSG_STRUCT_SENDOPT);
+  // releases send_opt
+  std::unique_ptr<std::remove_pointer<msg_struct_t*>::type, decltype(&msg_release_struct)>
+      send_opt_ptr(&send_opt, &msg_release_struct);
+
   msg_set_bool_value(send_opt, MSG_SEND_OPT_SETTING_BOOL, false);
   const int msg_id = msg_add_message(m_msg_handle, platform_msg, send_opt);
   if (msg_id < MSG_SUCCESS) {
-    msg_release_struct(&send_opt);
-    msg_release_struct(&platform_msg);
     return LogAndCreateResult(
         ErrorCode::UNKNOWN_ERR, "Cannot add message to draft",
         ("Message(%p): Failed to add draft, error: %d", message.get(), msg_id));
@@ -141,6 +146,9 @@ PlatformResult ShortMsgManager::addDraftMessagePlatform(std::shared_ptr<Message>
   message->setMessageStatus(MessageStatus::STATUS_DRAFT);
 
   msg_struct_t msg_conv = msg_create_struct(MSG_STRUCT_CONV_INFO);
+  // releases msg_conv
+  std::unique_ptr<std::remove_pointer<msg_struct_t*>::type, decltype(&msg_release_struct)>
+      msg_conv_ptr(&msg_conv, &msg_release_struct);
   msg_error_t err = msg_get_conversation(m_msg_handle, msg_id, msg_conv);
   if (MSG_SUCCESS == err) {
     int conversationId = 0;
@@ -170,15 +178,6 @@ PlatformResult ShortMsgManager::addDraftMessagePlatform(std::shared_ptr<Message>
   const int inResponseTo = msgInfo->getInResponseTo();
   message->setInResponseTo(inResponseTo);
 
-  if (msg_release_struct(&platform_msg) != MSG_SUCCESS) {
-    LoggerW("Platform message is already destroyed");
-  }
-  if (msg_release_struct(&msg_conv) != MSG_SUCCESS) {
-    LoggerW("Platform message is already destroyed");
-  }
-  if (msg_release_struct(&send_opt) != MSG_SUCCESS) {
-    LoggerW("Platform message is already destroyed");
-  }
   delete msgInfo;
   return PlatformResult(ErrorCode::NO_ERROR);
 }