Change codes to extract appinfo nodes from hashtable
authorJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 11 Mar 2021 02:30:44 +0000 (11:30 +0900)
committer연정현/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <jungh.yeon@samsung.com>
Thu, 11 Mar 2021 05:45:23 +0000 (14:45 +0900)
- Use g_hash_table_foreach_steal to extract node without free it.

Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/database/appinfo_db_handler.cc

index a31d67a..9c04a72 100644 (file)
 
 namespace {
 
-void _move(gpointer key, gpointer value, gpointer user_data) {
+gboolean _move_func(gpointer key, gpointer value, gpointer user_data) {
   application_x* appinfo = static_cast<application_x*>(value);
   std::vector<application_x*>* app_list =
       static_cast<std::vector<application_x*>*>(user_data);
   app_list->emplace_back(appinfo);
+  return true;
+}
+
+void __free_applications(gpointer data) {
+  pkgmgrinfo_basic_free_application((application_x*)data);
 }
 
 }  // namespace
@@ -55,7 +60,7 @@ int AppInfoDBHandler::Execute() {
   if (!Connect()) return PMINFO_R_ERROR;
 
   GHashTable* list = g_hash_table_new_full(g_str_hash, g_str_equal,
-      NULL, NULL);
+      NULL, __free_applications);
   std::vector<sqlite3*> conn_list = GetConnection();
   int ret = PMINFO_R_OK;
   for (auto conn : conn_list) {
@@ -63,12 +68,13 @@ int AppInfoDBHandler::Execute() {
                                              GetLocale().c_str(), list);
     if (ret == PMINFO_R_ERROR) {
       _LOGE("Failed to appinfo_internal_filter_get_list (%d)", ret);
-      g_hash_table_destroy(list);
       break;
     }
   }
 
-  g_hash_table_foreach(list, _move, &handle_list_);
+  if (ret == PMINFO_R_OK)
+    g_hash_table_foreach_steal(list, _move_func, &handle_list_);
+
   g_hash_table_destroy(list);
   return ret;
 }