Fix static analysis issues 12/248612/3
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 1 Dec 2020 01:49:39 +0000 (10:49 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 1 Dec 2020 23:45:25 +0000 (23:45 +0000)
Change-Id: I4865c112274c9aec03770aebe59cff8ec2b180c0
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/pkg_upgrade/src/main.cc
src/pkg_upgrade/src/upgrader.cc
src/pkgcmd/pkg_cmd.c

index 9d2eea2..dc3e8d4 100644 (file)
  * limitations under the License.
  */
 
+#include "logging.hh"
 #include "pkg_finder.hh"
 #include "upgrader.hh"
 
 int main(int argc, char *argv[]) {
-  common_fota::PkgFinder finder;
-  common_fota::Upgrader upgrader;
+  try {
+    common_fota::PkgFinder finder;
+    common_fota::Upgrader upgrader;
 
-  if (!upgrader.Process(&finder))
+    if (!upgrader.Process(&finder))
+      return -1;
+  } catch (...) {
+    LOG(ERROR) << "Exception occured";
     return -1;
+  }
 
   return 0;
 }
index ea7f5b5..100e85f 100644 (file)
@@ -365,10 +365,25 @@ int Upgrader::MakeBackupDbs() {
   return 0;
 
 CATCH:
-  remove(parser_db_bck.c_str());
-  remove(parser_db_journal_bck.c_str());
-  remove(cert_db_bck.c_str());
-  remove(cert_db_journal_bck.c_str());
+  if (remove(parser_db_bck.c_str())) {
+    LOG(WARNING) << "cannot remove backup file("
+        << parser_db_bck << ") " << errno;
+  }
+
+  if (remove(parser_db_journal_bck.c_str())) {
+    LOG(WARNING) << "cannot remove backup file("
+        << parser_db_journal_bck << ") " << errno;
+  }
+
+  if (remove(cert_db_bck.c_str())) {
+    LOG(WARNING) << "cannot remove backup file("
+        << cert_db_bck << ") " << errno;
+  }
+
+  if (remove(cert_db_journal_bck.c_str())) {
+    LOG(WARNING) << "cannot remove backup file("
+        << cert_db_journal_bck << ") " << errno;
+  }
 
   return -1;
 }
index 75e1ef4..0a9ee9b 100644 (file)
@@ -626,6 +626,10 @@ static int __install_multiple_pkgs(pkgmgr_client *pc, pm_tool_args *data,
        n_pkgs = g_list_length(data->pkgs);
 
        pkgs = malloc(sizeof(char *) * n_pkgs);
+       if (pkgs == NULL) {
+               printf("Out of memory\n");
+               return -1;
+       }
        for (l = data->pkgs, i = 0; l; l = l->next, i++)
                pkgs[i] = (char *)l->data;
 
@@ -708,6 +712,10 @@ static int __uninstall_multiple_pkgs(pkgmgr_client *pc, pm_tool_args *data,
        n_pkgs = g_list_length(data->pkgs);
 
        pkgs = malloc(sizeof(char *) * n_pkgs);
+       if (pkgs == NULL) {
+               printf("Out of memory\n");
+               return -1;
+       }
        for (l = data->pkgs, i = 0; l; l = l->next, i++)
                pkgs[i] = (char *)l->data;
 
@@ -828,6 +836,10 @@ static int __mount_install_multiple_pkgs(pkgmgr_client *pc, pm_tool_args *data,
        n_pkgs = g_list_length(data->pkgs);
 
        pkgs = malloc(sizeof(char *) * n_pkgs);
+       if (pkgs == NULL) {
+               printf("Out of memory\n");
+               return -1;
+       }
        for (l = data->pkgs, i = 0; l; l = l->next, i++)
                pkgs[i] = (char *)l->data;