Call abort() when double free occurs 11/286011/1
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 26 Dec 2022 05:14:37 +0000 (05:14 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 26 Dec 2022 05:14:37 +0000 (05:14 +0000)
When double free occurs, rpc-port library calls abort().
This is for deubgging C# applications.

Change-Id: I15465d756f8b17d21b4b56bb2938cb2c8b536fe4
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/rpc-port.cc

index 6d38540..88799b0 100644 (file)
@@ -297,6 +297,11 @@ RPC_API int rpc_port_proxy_destroy(rpc_port_proxy_h h) {
 
   auto p = static_cast<std::shared_ptr<::ProxyExt>*>(h);
   auto* proxy = p->get();
+  if (proxy->IsDestroying()) {
+    _E("already destroyed. handle(%p)", proxy);
+    abort();
+  }
+
   _W("rpc_port_proxy_destroy(%p)", proxy);
   if (getpid() == gettid()) {
     delete p;
@@ -434,6 +439,12 @@ RPC_API int rpc_port_stub_destroy(rpc_port_stub_h h) {
 
   _W("rpc_port_stub_destroy(%p)", h);
   auto p = static_cast<::StubExt*>(h);
+  if (p->IsDestroying()) {
+    _E("already destroyed. handle(%p)", h);
+    abort();
+  }
+
+  p->SetDestroying(true);
   aul_rpc_port_usr_destroy(p->GetPortName().c_str(), rpc_port_get_target_uid());
   if (getpid() == gettid()) {
     delete p;
@@ -441,7 +452,6 @@ RPC_API int rpc_port_stub_destroy(rpc_port_stub_h h) {
   }
 
   p->Ignore();
-  p->SetDestroying(true);
   g_idle_add_full(G_PRIORITY_HIGH,
       [](gpointer data) -> gboolean {
         auto p = static_cast<::StubExt*>(data);