Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 55a12544 authored by Steven Moreland's avatar Steven Moreland
Browse files

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
parent b8ba6e9c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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;
}
+7 −0
Original line number Diff line number Diff line
@@ -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());
}