Fix memory leak related to gdbus method call 95/246495/4
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 30 Oct 2020 05:13:19 +0000 (14:13 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 30 Oct 2020 05:19:38 +0000 (14:19 +0900)
Change-Id: I5b853f53378472eb3003dc7f13f9f86ab991fc4f
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
notification-ex/dbus_sender.cc

index b41f384..ba0d8f9 100644 (file)
@@ -140,6 +140,7 @@ GDBusMessage* DBusSender::Impl::MethodCall(string appid, string method_name,
     g_error_free(err);
   }
 
+  g_object_unref(msg);
   return reply;
 }
 
@@ -186,6 +187,7 @@ GDBusMessage* DBusSender::Impl::MethodCall(string appid, const IEventInfo& info,
   }
 
   g_variant_builder_unref(builder);
+  g_object_unref(msg);
   return reply;
 }
 
@@ -234,6 +236,9 @@ std::list<Bundle> DBusSender::Request(const IEventInfo& info) {
   if (!reply)
     return ret_list;
 
+  auto reply_ptr = std::unique_ptr<GDBusMessage, decltype(g_object_unref)*>(
+      reply, g_object_unref);
+
   GError* err = nullptr;
   if (g_dbus_message_to_gerror(reply, &err)) {
     LOGE("Request got error %s", err->message);
@@ -274,6 +279,9 @@ int DBusSender::RequestNumber(const IEventInfo& info) {
   if (!reply)
     return 0;
 
+  auto reply_ptr = std::unique_ptr<GDBusMessage, decltype(g_object_unref)*>(
+      reply, g_object_unref);
+
   GError* err = nullptr;
   if (g_dbus_message_to_gerror(reply, &err)) {
     LOGE("RequestNumber got error %s", err->message);