diff options
-rw-r--r-- | dbus/bus.cc | 6 | ||||
-rw-r--r-- | dbus/bus_unittest.cc | 4 | ||||
-rw-r--r-- | dbus/exported_object.h | 2 | ||||
-rw-r--r-- | dbus/object_proxy.h | 2 |
4 files changed, 12 insertions, 2 deletions
diff --git a/dbus/bus.cc b/dbus/bus.cc index 858f686..e0ef031 100644 --- a/dbus/bus.cc +++ b/dbus/bus.cc @@ -293,6 +293,12 @@ void Bus::ShutdownAndBlock() { iter->second->Detach(); } + // Release object proxies and exported objects here. We should do this + // here rather than in the destructor to avoid memory leaks due to + // cyclic references. + object_proxy_table_.clear(); + exported_object_table_.clear(); + // Private connection should be closed. if (connection_) { if (connection_type_ == PRIVATE) diff --git a/dbus/bus_unittest.cc b/dbus/bus_unittest.cc index 999727a..bbd2a4c 100644 --- a/dbus/bus_unittest.cc +++ b/dbus/bus_unittest.cc @@ -46,6 +46,8 @@ TEST(BusTest, GetObjectProxy) { "/org/chromium/DifferentTestObject"); ASSERT_TRUE(object_proxy3); EXPECT_NE(object_proxy1, object_proxy3); + + bus->ShutdownAndBlock(); } TEST(BusTest, GetExportedObject) { @@ -70,6 +72,8 @@ TEST(BusTest, GetExportedObject) { "/org/chromium/DifferentTestObject"); ASSERT_TRUE(object_proxy3); EXPECT_NE(object_proxy1, object_proxy3); + + bus->ShutdownAndBlock(); } TEST(BusTest, ShutdownAndBlock) { diff --git a/dbus/exported_object.h b/dbus/exported_object.h index 24456f7..7dd8ca5 100644 --- a/dbus/exported_object.h +++ b/dbus/exported_object.h @@ -144,7 +144,7 @@ class ExportedObject : public base::RefCountedThreadSafe<ExportedObject> { static void OnUnregisteredThunk(DBusConnection* connection, void* user_data); - Bus* bus_; + scoped_refptr<Bus> bus_; std::string service_name_; std::string object_path_; bool object_is_registered_; diff --git a/dbus/object_proxy.h b/dbus/object_proxy.h index a950e94..5fc4197 100644 --- a/dbus/object_proxy.h +++ b/dbus/object_proxy.h @@ -175,7 +175,7 @@ class ObjectProxy : public base::RefCountedThreadSafe<ObjectProxy> { DBusMessage* raw_message, void* user_data); - Bus* bus_; + scoped_refptr<Bus> bus_; std::string service_name_; std::string object_path_; |