Fix static analysis issues 53/313653/1
authorSangyoon Jang <jeremy.jang@samsung.com>
Sun, 30 Jun 2024 23:47:20 +0000 (08:47 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Sun, 30 Jun 2024 23:47:20 +0000 (08:47 +0900)
Change-Id: Ia2792fb8cdf2a3dd7af672c37aaad5b210025b8d
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/api/theme_loader.cc
src/theme_plugin/theme_metadata_plugin.cc

index 4d43308e8a66fc058357061e9c91cf042ef10da0..a2b89c11ecfb63f199de90a4addaccd247f7b765 100644 (file)
@@ -65,9 +65,11 @@ extern "C" EXPORT_API int theme_loader_create(theme_loader_h* handle) {
     return THEME_MANAGER_ERROR_INVALID_PARAMETER;
   }
 
-  auto* p = new std::shared_ptr<ThemeInfoLoader>(
-      std::make_shared<ThemeInfoLoader>());
-  if (p == nullptr) {
+  std::shared_ptr<ThemeInfoLoader>* p;
+  try {
+    p = new std::shared_ptr<ThemeInfoLoader>(
+        std::make_shared<ThemeInfoLoader>());
+  } catch (const std::bad_alloc& e) {
     LOG(ERROR) << "Out of memory";
     return THEME_MANAGER_ERROR_OUT_OF_MEMORY;
   }
@@ -105,7 +107,15 @@ extern "C" EXPORT_API int theme_loader_load_current(theme_loader_h handle,
     LOG(ERROR) << "Failed to load current theme";
     return THEME_MANAGER_ERROR_NO_SUCH_THEME;
   }
-  *cur_theme = static_cast<theme_h>(new std::shared_ptr<ThemeInfo>(theme_info));
+
+  try {
+    *cur_theme = static_cast<theme_h>(
+        new std::shared_ptr<ThemeInfo>(theme_info));
+  } catch (const std::bad_alloc& e) {
+    LOG(ERROR) << "Out of memory";
+    return THEME_MANAGER_ERROR_OUT_OF_MEMORY;
+  }
+
   return THEME_MANAGER_ERROR_NONE;
 }
 
@@ -124,7 +134,14 @@ extern "C" EXPORT_API int theme_loader_load(theme_loader_h handle,
     LOG(ERROR) << "Failed to load theme " << id;
     return THEME_MANAGER_ERROR_NO_SUCH_THEME;
   }
-  *theme = static_cast<theme_h>(new std::shared_ptr<ThemeInfo>(theme_info));
+
+  try {
+    *theme = static_cast<theme_h>(new std::shared_ptr<ThemeInfo>(theme_info));
+  } catch (const std::bad_alloc& e) {
+    LOG(ERROR) << "Out of memory";
+    return THEME_MANAGER_ERROR_OUT_OF_MEMORY;
+  }
+
   return THEME_MANAGER_ERROR_NONE;
 }
 
@@ -172,9 +189,10 @@ extern "C" EXPORT_API int theme_loader_add_event(theme_loader_h handle,
     return THEME_MANAGER_ERROR_INVALID_PARAMETER;
   }
 
-  std::shared_ptr<IThemeEvent> event_handler(new ThemeEventHandler(
-      changed, user_data));
-  if (event_handler.get() == nullptr) {
+  std::shared_ptr<IThemeEvent> event_handler;
+  try {
+    event_handler = std::make_shared<ThemeEventHandler>(changed, user_data);
+  } catch (const std::bad_alloc& e) {
     LOG(ERROR) << "Out of memory";
     return THEME_MANAGER_ERROR_OUT_OF_MEMORY;
   }
index 8a439690565969cad354c7af53b1602913ff161e..d8500755c0dfa075706de5605a7d5a0e4777a60f 100644 (file)
@@ -54,11 +54,8 @@ bool ParseAndCommitTheme(ThemeParser::ThemeOperation op, const std::string& id,
     const std::string& pkgid, const std::string& path, bool is_default,
     bool auto_file_key_gen) {
   uid_t uid;
-  int r = pkgmgr_installer_info_get_target_uid(&uid);
-  if (r < 0) {
-    LOG(ERROR) << "Failed to get target uid";
-    return false;
-  }
+  // always return 0
+  pkgmgr_installer_info_get_target_uid(&uid);
 
   ThemeParser parser(path, auto_file_key_gen);
   ThemeInfo theme = parser.Inflate(id, pkgid, uid, is_default);