diff options
author | Peter Qiu <zqiu@google.com> | 2015-08-27 11:37:07 -0700 |
---|---|---|
committer | Peter Qiu <zqiu@google.com> | 2015-08-28 16:11:21 -0700 |
commit | a31c5257ce2673c8cdcb8e43e2a1dd40e926009d (patch) | |
tree | 27b5851de9a015c2cd7bd5f2c25a6805e8963dac | |
parent | a0a75b2804a64ef1415d05ef77dfb1ad58f178b0 (diff) | |
download | dbus-binding-generator-a31c5257ce2673c8cdcb8e43e2a1dd40e926009d.tar.gz |
chromeos-dbus-bindings: remove object proxy from bus in proxy destructor
This will free up resources that the bus allocated for the given proxy,
avoid any memory/resource leak.
BUG=23560086
TEST=unittest
TEST=Verify generated proxy code
Change-Id: I0e6b7387ee01cbd4564174f0a8817aa784fd6295
-rw-r--r-- | chromeos-dbus-bindings/proxy_generator.cc | 6 | ||||
-rw-r--r-- | chromeos-dbus-bindings/proxy_generator_unittest.cc | 16 |
2 files changed, 22 insertions, 0 deletions
diff --git a/chromeos-dbus-bindings/proxy_generator.cc b/chromeos-dbus-bindings/proxy_generator.cc index 717740d..396c3d0 100644 --- a/chromeos-dbus-bindings/proxy_generator.cc +++ b/chromeos-dbus-bindings/proxy_generator.cc @@ -399,6 +399,12 @@ void ProxyGenerator::AddDestructor(const string& class_name, IndentedText* text) { IndentedText block; block.AddLine(StringPrintf("~%s() override {", class_name.c_str())); + block.PushOffset(kBlockOffset); + block.AddLine("bus_->RemoveObjectProxy("); + block.AddLineWithOffset( + "service_name_, object_path_, base::Bind(&base::DoNothing));", + kLineContinuationOffset); + block.PopOffset(); block.AddLine("}"); text->AddBlock(block); } diff --git a/chromeos-dbus-bindings/proxy_generator_unittest.cc b/chromeos-dbus-bindings/proxy_generator_unittest.cc index 75b7e9f..9eb930f 100644 --- a/chromeos-dbus-bindings/proxy_generator_unittest.cc +++ b/chromeos-dbus-bindings/proxy_generator_unittest.cc @@ -138,6 +138,8 @@ class TestInterfaceProxy final : public TestInterfaceProxyInterface { } ~TestInterfaceProxy() override { + bus_->RemoveObjectProxy( + service_name_, object_path_, base::Bind(&base::DoNothing)); } void RegisterCloserSignalHandler( @@ -348,6 +350,8 @@ class TestInterface2Proxy final : public TestInterface2ProxyInterface { } ~TestInterface2Proxy() override { + bus_->RemoveObjectProxy( + service_name_, object_path_, base::Bind(&base::DoNothing)); } void ReleaseObjectProxy(const base::Closure& callback) { @@ -452,6 +456,8 @@ class TestInterfaceProxy final : public TestInterfaceProxyInterface { } ~TestInterfaceProxy() override { + bus_->RemoveObjectProxy( + service_name_, object_path_, base::Bind(&base::DoNothing)); } void RegisterCloserSignalHandler( @@ -515,6 +521,8 @@ class TestInterface2Proxy final : public TestInterface2ProxyInterface { } ~TestInterface2Proxy() override { + bus_->RemoveObjectProxy( + service_name_, object_path_, base::Bind(&base::DoNothing)); } void ReleaseObjectProxy(const base::Closure& callback) { @@ -621,6 +629,8 @@ class Itf1Proxy final : public Itf1ProxyInterface { } ~Itf1Proxy() override { + bus_->RemoveObjectProxy( + service_name_, object_path_, base::Bind(&base::DoNothing)); } void RegisterCloserSignalHandler( @@ -720,6 +730,8 @@ class Itf2Proxy final : public Itf2ProxyInterface { } ~Itf2Proxy() override { + bus_->RemoveObjectProxy( + service_name_, object_path_, base::Bind(&base::DoNothing)); } void ReleaseObjectProxy(const base::Closure& callback) { @@ -993,6 +1005,8 @@ class Itf1Proxy final : public Itf1ProxyInterface { } ~Itf1Proxy() override { + bus_->RemoveObjectProxy( + service_name_, object_path_, base::Bind(&base::DoNothing)); } void RegisterCloserSignalHandler( @@ -1070,6 +1084,8 @@ class Itf2Proxy final : public Itf2ProxyInterface { } ~Itf2Proxy() override { + bus_->RemoveObjectProxy( + service_name_, object_path_, base::Bind(&base::DoNothing)); } void ReleaseObjectProxy(const base::Closure& callback) { |