From: Ilho Kim Date: Mon, 4 Jul 2022 04:14:07 +0000 (+0900) Subject: Fix static analysis issues X-Git-Tag: accepted/tizen/unified/20220705.211016~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F37%2F277237%2F1;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git Fix static analysis issues - Resource leak - Pointer to local outside scope Change-Id: I3445d458c28a448d6c873bea862712d47c669096 Signed-off-by: Ilho Kim --- diff --git a/src/pkgmgrinfo_private.c b/src/pkgmgrinfo_private.c index 003d77e..1ace1b5 100644 --- a/src/pkgmgrinfo_private.c +++ b/src/pkgmgrinfo_private.c @@ -586,16 +586,14 @@ API char *__get_type_from_path(const char *pkg_path) return strdup(type); } -static const char *__get_library_path(const char *pkg_type) +static void __get_library_path(const char *pkg_type, const char **path) { char buf[64]; - const char *path; snprintf(buf, sizeof(buf), "package-manager/backendlib/lib%s.so", pkg_type); - path = tzplatform_mkpath(TZ_SYS_RO_ETC, buf); - return path; + *path = tzplatform_mkpath(TZ_SYS_RO_ETC, buf); } API pkg_plugin_set *__load_library(const char *pkg_type) @@ -605,7 +603,7 @@ API pkg_plugin_set *__load_library(const char *pkg_type) bool (*on_load)(pkg_plugin_set *plugin); const char *library_path; - library_path = __get_library_path(pkg_type); + __get_library_path(pkg_type, &library_path); if (library_path == NULL) { _LOGE("cannot get library path for %s", pkg_type); return NULL; diff --git a/src/server/database/db_handle_provider.cc b/src/server/database/db_handle_provider.cc index 1e88c35..14c3f30 100644 --- a/src/server/database/db_handle_provider.cc +++ b/src/server/database/db_handle_provider.cc @@ -336,12 +336,6 @@ int DBHandleProvider::UpdateCache(sqlite3* db, pid_t pid, uid_t uid, bool write, pkg_map_.clear(); app_map_.clear(); - GHashTable* list = g_hash_table_new(g_str_hash, g_str_equal); - if (list == nullptr) { - LOG(ERROR) << "Out of memory"; - return PMINFO_R_ERROR; - } - const char* dbpath = sqlite3_db_filename(db, "main"); bool is_inmemory_db = false; if (dbpath == nullptr || strlen(dbpath) == 0) { @@ -354,6 +348,12 @@ int DBHandleProvider::UpdateCache(sqlite3* db, pid_t pid, uid_t uid, bool write, if (!is_inmemory_db && !GetModifiedTime(dbpath, &start_time)) return PMINFO_R_ERROR; + GHashTable* list = g_hash_table_new(g_str_hash, g_str_equal); + if (list == nullptr) { + LOG(ERROR) << "Out of memory"; + return PMINFO_R_ERROR; + } + pkgmgrinfo_filter_x tmp_filter = { 0, }; int ret = pkginfo_internal_filter_get_list(db, &tmp_filter, uid_, locale.c_str(), list);