Fix static analyzer issues 21/196721/1
authorSangyoon Jang <jeremy.jang@samsung.com>
Thu, 22 Mar 2018 06:52:28 +0000 (15:52 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Fri, 4 Jan 2019 02:19:25 +0000 (11:19 +0900)
- Fix memory leak
- Fix using uninitialized variables
- Fix dereferencing before null check

Change-Id: I119e803a3e9acb9e63abc1f28c2fbd93f7e92699
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/hybrid/step/pkgmgr/step_generate_xml.h
src/unit_tests/extensive_smoke_test.cc
src/wgt/step/configuration/step_parse.cc
src/wgt/step/encryption/step_encrypt_resources.h
src/wgt/step/filesystem/step_wgt_patch_icons.cc

index b2a0f6e..8fce64d 100644 (file)
@@ -19,6 +19,8 @@ namespace pkgmgr {
 class StepGenerateXml : public common_installer::Step {
  public:
   using Step::Step;
+  explicit StepGenerateXml(common_installer::InstallerContext* context)
+      : Step(context), wgt_doc_(nullptr), tpk_doc_(nullptr) {}
   Status process() override;
   Status clean() override { return Status::OK; }
   Status undo() override { return Status::OK; }
index 34104de..b03d2bc 100644 (file)
@@ -379,15 +379,20 @@ TEST_F(SmokeTest, MountUpdateMode_Rollback) {
 }  // namespace common_installer
 
 int main(int argc,  char** argv) {
-  ci::RequestMode request_mode = ParseRequestMode(argc, argv);
-  if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL) {
-    std::cout << "Skip tests for preload request" << std::endl;
-    ::testing::GTEST_FLAG(filter) = "SmokeTest.*";
+  try {
+    ci::RequestMode request_mode = ParseRequestMode(argc, argv);
+    if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL) {
+      std::cout << "Skip tests for preload request" << std::endl;
+      ::testing::GTEST_FLAG(filter) = "SmokeTest.*";
+    }
+    testing::InitGoogleTest(&argc, argv);
+    env = testing::AddGlobalTestEnvironment(
+        new common_installer::SmokeEnvironment(request_mode));
+    signal(SIGINT, signalHandler);
+    signal(SIGSEGV, signalHandler);
+    return RUN_ALL_TESTS();
+  } catch (...) {
+    std::cout << "Exception occurred during testing";
+    return 1;
   }
-  testing::InitGoogleTest(&argc, argv);
-  env = testing::AddGlobalTestEnvironment(
-      new common_installer::SmokeEnvironment(request_mode));
-  signal(SIGINT, signalHandler);
-  signal(SIGSEGV, signalHandler);
-  return RUN_ALL_TESTS();
 }
index 3252489..d522b5a 100644 (file)
@@ -490,6 +490,7 @@ bool StepParse::FillServiceApplicationInfo(manifest_x* manifest) {
           calloc(1, sizeof(metadata_x)));
       if (!item) {
         LOG(ERROR) << "Out of memory";
+        pkgmgrinfo_basic_free_application(application);
         return false;
       }
       item->key = strdup(pair.first.c_str());
@@ -946,6 +947,7 @@ common_installer::Step::Status StepParse::process() {
   if (!FillManifestX(manifest)) {
     LOG(ERROR) << "[Parse] Storing manifest_x failed. "
                <<  parser_->GetErrorMessage();
+    pkgmgr_parser_free_manifest_xml(manifest);
     return common_installer::Step::Status::PARSE_ERROR;
   }
 
index 27e4d02..6b420fd 100644 (file)
@@ -22,6 +22,9 @@ class StepEncryptResources : public common_installer::Step {
  public:
   using Step::Step;
 
+  explicit StepEncryptResources(common_installer::InstallerContext* context)
+      : Step(context), backend_data_(nullptr) {}
+
   /**
    * \brief Encrypt files
    *
index 89e6fff..c48e381 100644 (file)
@@ -18,6 +18,8 @@ namespace {
 const char kDefaultIconPath[] = "/usr/share/wgt-backend/default.png";
 
 bool PatchIcon(icon_x* icon, const bf::path& dst_path) {
+  if (!icon)
+    return false;
   bs::error_code error;
   bf::path icon_text(icon->text);
   bf::path icon_path = dst_path;