diff options
| author | 2022-03-31 21:53:11 +0000 | |
|---|---|---|
| committer | 2022-03-31 21:53:11 +0000 | |
| commit | 55a125443048bbf908790c75fa91c7741c297209 (patch) | |
| tree | 04c1c8897f98a61fa2ac47b7df73ff1bb740e5b8 | |
| parent | b8ba6e9cc036c9face3ab1c738fdc51cfd499323 (diff) | |
libbinder: add log for dropped extension
In the NDK/Rust backend, it's pretty easy to create a binder, attach
an extension to it, and then immediately destroy that binder.
Here, I add a log when this happens and add a unit test for BBinder
which triggers this path (it's never expected to be hit in practice
since binders aren't created without being sent).
Bug: N/A
Test: binderUnitTests
Change-Id: Id2b51396b027530e3fad767f698a3b2cecbfa98d
| -rw-r--r-- | libs/binder/Binder.cpp | 4 | ||||
| -rw-r--r-- | libs/binder/tests/binderBinderUnitTest.cpp | 7 |
2 files changed, 11 insertions, 0 deletions
diff --git a/libs/binder/Binder.cpp b/libs/binder/Binder.cpp index 01b25d390d..39befbe8e0 100644 --- a/libs/binder/Binder.cpp +++ b/libs/binder/Binder.cpp @@ -582,6 +582,10 @@ void BBinder::removeRpcServerLink(const sp<RpcServerLink>& link) { BBinder::~BBinder() { + if (!wasParceled() && getExtension()) { + ALOGW("Binder %p destroyed with extension attached before being parceled.", this); + } + Extras* e = mExtras.load(std::memory_order_relaxed); if (e) delete e; } diff --git a/libs/binder/tests/binderBinderUnitTest.cpp b/libs/binder/tests/binderBinderUnitTest.cpp index 1be0c59c78..ce2770f943 100644 --- a/libs/binder/tests/binderBinderUnitTest.cpp +++ b/libs/binder/tests/binderBinderUnitTest.cpp @@ -41,3 +41,10 @@ TEST(Binder, DetachObject) { EXPECT_EQ(kObject1, binder->detachObject(kObjectId1)); EXPECT_EQ(nullptr, binder->attachObject(kObjectId1, kObject2, nullptr, nullptr)); } + +TEST(Binder, AttachExtension) { + auto binder = sp<BBinder>::make(); + auto ext = sp<BBinder>::make(); + binder->setExtension(ext); + EXPECT_EQ(ext, binder->getExtension()); +} |