Proxy onLastStrongRef: clear DRs
In case unlinkToDeath isn't called.
Bug: 134576445
Test: manually checking refs in /d/binder
Change-Id: I905be138d13ce61c5debb4321118ea783206f762
diff --git a/generateCpp.cpp b/generateCpp.cpp
index cf8381e..9e9b348 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -789,6 +789,8 @@
out << "virtual bool isRemote() const override { return true; }\n\n";
+ out << "void onLastStrongRef(const void* id) override;\n\n";
+
generateMethods(
out,
[&](const Method* method, const Interface*) {
@@ -1240,6 +1242,18 @@
out.unindent();
out << "}\n\n";
+ out << "void " << klassName << "::onLastStrongRef(const void* id) ";
+ out.block([&] {
+ out.block([&] {
+ // if unlinkToDeath is not used, remove strong cycle between
+ // this and hidl_binder_death_recipient
+ out << "std::unique_lock<std::mutex> lock(_hidl_mMutex);\n";
+ out << "_hidl_mDeathRecipients.clear();\n";
+ }).endl().endl();
+
+ out << "BpInterface<" << fqName.getInterfaceName() << ">::onLastStrongRef(id);\n";
+ }).endl();
+
generateMethods(out,
[&](const Method* method, const Interface* superInterface) {
generateStaticProxyMethodSource(out, klassName, method, superInterface);