From: Hwankyu Jhun Date: Mon, 19 Sep 2022 07:45:29 +0000 (+0000) Subject: Fix resource leak X-Git-Tag: accepted/tizen/unified/20220920.050145~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ab8d49d2fdf501ced10464e69275c8de86eced5f;p=platform%2Fcore%2Fappfw%2Flaunchpad.git Fix resource leak The allocated memory has to be released. The xmlGetProp() returns the allocated value. It should be released using xmlFree(). Change-Id: I031d76c587ad8dcab9141c585d732893d916eea9 Signed-off-by: Hwankyu Jhun --- diff --git a/src/launchpad-parser/launchpad_parser_plugin.cc b/src/launchpad-parser/launchpad_parser_plugin.cc index f8736732..d8b23c08 100644 --- a/src/launchpad-parser/launchpad_parser_plugin.cc +++ b/src/launchpad-parser/launchpad_parser_plugin.cc @@ -103,15 +103,21 @@ int LaunchpadParser::Install(xmlDocPtr doc, std::string pkgid) { continue; xmlChar* val = xmlGetProp(node, reinterpret_cast("id")); + if (val == nullptr) + continue; + std::shared_ptr info = std::make_shared(std::string(reinterpret_cast(val))); + xmlFree(val); if (!IsValidId(info->GetId(), pkgid)) return -1; xmlChar* ttl = xmlGetProp(node, reinterpret_cast("time-to-live")); - if (ttl) + if (ttl) { info->SetTimeToLive(std::stoi(std::string(reinterpret_cast(ttl)))); + xmlFree(ttl); + } for (xmlNode* iter = node->children; iter; iter = iter->next) { if (!iter->name) @@ -120,10 +126,11 @@ int LaunchpadParser::Install(xmlDocPtr doc, std::string pkgid) { std::string(reinterpret_cast(iter->name)); if (child_name == "preload-library") { xmlChar* libname = xmlGetProp(iter, - reinterpret_cast("name")); + reinterpret_cast("name")); if (!libname) continue; info->AddPreloadLib(std::string(reinterpret_cast(libname))); + xmlFree(libname); } } loader_list_.push_back(info); @@ -158,6 +165,7 @@ int LaunchpadParser::UnInstall(xmlDocPtr doc, std::string pkgid) { return -1; std::string id = std::string(reinterpret_cast(val)); + xmlFree(val); if (!IsValidId(id, pkgid)) return -1; remove(GetFilePath(id).c_str());