Fix static analysis issues 37/277237/1
authorIlho Kim <ilho159.kim@samsung.com>
Mon, 4 Jul 2022 04:14:07 +0000 (13:14 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Mon, 4 Jul 2022 04:52:21 +0000 (13:52 +0900)
- Resource leak
- Pointer to local outside scope

Change-Id: I3445d458c28a448d6c873bea862712d47c669096
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/pkgmgrinfo_private.c
src/server/database/db_handle_provider.cc

index 003d77e..1ace1b5 100644 (file)
@@ -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;
index 1e88c35..14c3f30 100644 (file)
@@ -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);