Check G_IO_ERROR_CANCELLED error 93/283993/1
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 8 Nov 2022 07:46:41 +0000 (07:46 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 8 Nov 2022 07:46:41 +0000 (07:46 +0000)
This patch checks whether the error is G_IO_ERROR_CANCELLED or not before
accessing the user data. If the error is G_IO_ERROR_CANCELLED, rpc-port
returns immediately.

Change-Id: I5936d2be3b38c3d15fed9cbcabc0fe1457015f78
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/fdbroker-internal.cc

index 39099e1883de3e70470f752160458fd24bfb6e06..5f54b8127bb739b5914d86e212586ee62ac20161 100644 (file)
@@ -835,6 +835,18 @@ void FdBroker::OnResultReceived(GObject* source_object,
                                 GAsyncResult* res,
                                 gpointer user_data) {
   _W("OnResultReceived()");
+  GDBusConnection* conn = reinterpret_cast<GDBusConnection*>(source_object);
+  GError* err = nullptr;
+  GDBusMessage* reply = g_dbus_connection_send_message_with_reply_finish(conn,
+      res, &err);
+  if (err != nullptr) {
+    if (err->code == G_IO_ERROR_CANCELLED) {
+      _E("G_IO_ERROR_CANCELLED");
+      g_error_free(err);
+      return;
+    }
+  }
+
   auto* ptr = static_cast<std::weak_ptr<FdBroker>*>(user_data);
   auto broker = ptr->lock();
   if (broker == nullptr) {
@@ -849,20 +861,14 @@ void FdBroker::OnResultReceived(GObject* source_object,
   }
 
   IEventWatcher* watcher = broker->watcher_;
-  GDBusConnection* conn = reinterpret_cast<GDBusConnection*>(source_object);
-  GError* err = nullptr;
-  GDBusMessage* reply = g_dbus_connection_send_message_with_reply_finish(conn,
-      res, &err);
   if (reply == nullptr) {
     if (err) {
-      if (err->code == G_IO_ERROR_CANCELLED)
-        _E("IO error cancelled");
-      else
-        _E("Error(%s) occurs", err->message);
+      _E("Error(%s) occurs", err->message);
       g_error_free(err);
     } else {
       _E("g_dbus_connection_send_message_with_reply_finish() is failed");
     }
+
     watcher->OnPortDisconnected();
     return;
   }