Fix wrong throw exception 01/324501/2
authorChanggyu Choi <changyu.choi@samsung.com>
Tue, 20 May 2025 00:48:15 +0000 (09:48 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Tue, 20 May 2025 01:12:46 +0000 (10:12 +0900)
Change-Id: I89d6f6dc142f1775065e64fdfc0a792e37edeec9
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
src/activation_method/path_monitor.cc

index de8072def81ea36c792aac035add9463387a4e0d..63264ffe64aba210fd87706abf7558e97daedd64 100644 (file)
@@ -33,26 +33,24 @@ PathMonitor::PathMonitor(std::string name,
   dir_path_ = full_path.parent_path();
   target_name_ = full_path.filename().string();
   dir_ = g_file_new_for_path(dir_path_.c_str());
+  if (!dir_)
+    throw std::runtime_error("Failed to create directory");
+
   monitor_ =
       g_file_monitor_directory(dir_, G_FILE_MONITOR_NONE, nullptr, nullptr);
 
   if (monitor_ == nullptr) {
     g_object_unref(dir_);
-    dir_ = nullptr;
-    std::runtime_error("Failed to create monitor");
+    throw std::runtime_error("Failed to create monitor");
   }
 
   g_signal_connect(monitor_, "changed", G_CALLBACK(OnFileChanged), this);
   if (mode_ == PathInfo::Mode::Created && fs::exists(full_path, error)) {
-    if (monitor_) {
-      g_object_unref(monitor_);
-      monitor_ = nullptr;
-    }
-
-    if (dir_) {
-      g_object_unref(dir_);
-      dir_ = nullptr;
-    }
+    g_object_unref(monitor_);
+    monitor_ = nullptr;
+
+    g_object_unref(dir_);
+    dir_ = nullptr;
 
     NotifyEvent();
   }