From: Sangyoon Jang Date: Mon, 19 Sep 2022 08:15:01 +0000 (+0900) Subject: Fix static analysis issue X-Git-Tag: accepted/tizen/unified/20220921.091805~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4f568dfa8e73782b07f4e525484dbd480060adb2;p=platform%2Fcore%2Fappfw%2Ftpk-backend.git Fix static analysis issue Change-Id: I6a8a2b568828b4556da97099f9ba0488aeb1cb97 Signed-off-by: Sangyoon Jang --- diff --git a/src/tpk/step/pkgmgr/step_manifest_adjustment.cc b/src/tpk/step/pkgmgr/step_manifest_adjustment.cc index 8587f8c..64c5912 100644 --- a/src/tpk/step/pkgmgr/step_manifest_adjustment.cc +++ b/src/tpk/step/pkgmgr/step_manifest_adjustment.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include "common/utils/profile_util.h" #include "common/installer_context.h" @@ -74,43 +75,43 @@ common_installer::Step::Status StepManifestAdjustment::precheck() { } common_installer::Step::Status StepManifestAdjustment::process() { - xmlDocPtr doc = xmlParseFile(xml_path_.c_str()); + std::unique_ptr doc( + xmlParseFile(xml_path_.c_str()), xmlFreeDoc); - if (doc == nullptr) { + if (doc == nullptr || doc.get() == nullptr) { LOG(ERROR) << "Could not parse file"; return Step::Status::ERROR; } - xmlNodePtr node = xmlDocGetRootElement(doc); + xmlNodePtr node = xmlDocGetRootElement(doc.get()); + if (node == nullptr) { + LOG(ERROR) << "Could not get root element"; + return Step::Status::ERROR; + } if (!SetProperty(node, "type", context_->manifest_data.get()->type)) { - xmlFreeDoc(doc); return Step::Status::ERROR; } if (!SetProperty(node, "readonly", context_->manifest_data.get()->readonly)) { - xmlFreeDoc(doc); return Step::Status::ERROR; } if (!SetProperty(node, "preload", context_->manifest_data.get()->preload)) { - xmlFreeDoc(doc); return Step::Status::ERROR; } if (!SetProperty(node, "removable", context_->manifest_data.get()->removable)) { - xmlFreeDoc(doc); return Step::Status::ERROR; } if (IsNonPrivilegedPackage() && IsAdjustmentNecessary()) { - xmlXPathContextPtr xpath_ctx = xmlXPathNewContext(doc); + xmlXPathContextPtr xpath_ctx = xmlXPathNewContext(doc.get()); if (!xpath_ctx) { LOG(ERROR) << "Failed to create XPath context"; - xmlFreeDoc(doc); return Step::Status::ERROR; } @@ -135,7 +136,6 @@ common_installer::Step::Status StepManifestAdjustment::process() { !SetManifestElement(&(app->onboot), "false")) { xmlXPathFreeObject(xpath_obj); xmlXPathFreeContext(xpath_ctx); - xmlFreeDoc(doc); return Step::Status::ERROR; } @@ -144,14 +144,11 @@ common_installer::Step::Status StepManifestAdjustment::process() { xmlXPathFreeContext(xpath_ctx); } - if (xmlSaveFile(xml_path_.c_str(), doc) == -1) { + if (xmlSaveFile(xml_path_.c_str(), doc.get()) == -1) { LOG(ERROR) << "Failed to modify xml file"; - xmlFreeDoc(doc); return Step::Status::ERROR; } - xmlFreeDoc(doc); - return Step::Status::OK; }