From 077fc515c32d7f8c848b578243b3ecbb6fed45f7 Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Mon, 4 Jul 2022 13:14:07 +0900 Subject: [PATCH] Fix static analysis issues - Resource leak - Pointer to local outside scope Change-Id: I3445d458c28a448d6c873bea862712d47c669096 Signed-off-by: Ilho Kim --- src/pkgmgrinfo_private.c | 8 +++----- src/server/database/db_handle_provider.cc | 12 ++++++------ 2 files changed, 9 insertions(+), 11 deletions(-) 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); -- 2.7.4