From: Sangyoon Jang Date: Thu, 22 Mar 2018 06:52:28 +0000 (+0900) Subject: Fix static analyzer issues X-Git-Tag: accepted/tizen/unified/20180330.060619~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=80fb8bdc3b0d501411c263a19a609546711b9510;p=platform%2Fcore%2Fappfw%2Fwgt-backend.git Fix static analyzer issues - Fix memory leak - Fix using uninitialized variables - Fix dereferencing before null check Change-Id: I119e803a3e9acb9e63abc1f28c2fbd93f7e92699 Signed-off-by: Sangyoon Jang --- diff --git a/src/hybrid/step/pkgmgr/step_generate_xml.h b/src/hybrid/step/pkgmgr/step_generate_xml.h index b2a0f6e..8fce64d 100644 --- a/src/hybrid/step/pkgmgr/step_generate_xml.h +++ b/src/hybrid/step/pkgmgr/step_generate_xml.h @@ -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; } diff --git a/src/unit_tests/extensive_smoke_test.cc b/src/unit_tests/extensive_smoke_test.cc index 5c88971..1f0a8ab 100644 --- a/src/unit_tests/extensive_smoke_test.cc +++ b/src/unit_tests/extensive_smoke_test.cc @@ -419,16 +419,21 @@ TEST_F(SmokeTest, MountUpdateMode_Rollback) { } // namespace smoke_test int main(int argc, char** argv) { - ci::RequestMode request_mode = smoke_test::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 = smoke_test::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 = static_cast( + testing::AddGlobalTestEnvironment( + new smoke_test::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 = static_cast( - testing::AddGlobalTestEnvironment( - new smoke_test::SmokeEnvironment(request_mode))); - signal(SIGINT, ::signalHandler); - signal(SIGSEGV, ::signalHandler); - return RUN_ALL_TESTS(); } diff --git a/src/wgt/step/configuration/step_parse.cc b/src/wgt/step/configuration/step_parse.cc index 4447368..1637c54 100644 --- a/src/wgt/step/configuration/step_parse.cc +++ b/src/wgt/step/configuration/step_parse.cc @@ -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()); @@ -943,6 +944,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; } diff --git a/src/wgt/step/encryption/step_encrypt_resources.h b/src/wgt/step/encryption/step_encrypt_resources.h index 27e4d02..6b420fd 100644 --- a/src/wgt/step/encryption/step_encrypt_resources.h +++ b/src/wgt/step/encryption/step_encrypt_resources.h @@ -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 * diff --git a/src/wgt/step/filesystem/step_wgt_patch_icons.cc b/src/wgt/step/filesystem/step_wgt_patch_icons.cc index e0a1be0..b80263a 100644 --- a/src/wgt/step/filesystem/step_wgt_patch_icons.cc +++ b/src/wgt/step/filesystem/step_wgt_patch_icons.cc @@ -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;