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

Commit 383f61d9 authored by Pawin Vongmasa's avatar Pawin Vongmasa
Browse files

Release the mutex before calling hidl_cb

In Omx::allocateNode, Omx::serviceDied may be called by hidl_cb in
Omx::allocateNode if the observer dies before hidl_cb is called. This CL
prevents a deadlock from happening in this situation.

Test: make cts -j99 && cts-tradefed run cts-dev \
--module CtsMediaTestCases --compatibility:module-arg \
CtsMediaTestCases:include-annotation:\
android.platform.test.annotations.RequiresDevice
Bug: 63177989

Change-Id: I8e1357ff637b0912a3a97c6611d886533caaaf8a
parent d4ef5f1e
Loading
Loading
Loading
Loading
+38 −35
Original line number Diff line number Diff line
@@ -90,13 +90,15 @@ Return<void> Omx::allocateNode(
    using ::android::IOMXNode;
    using ::android::IOMXObserver;

    sp<OMXNodeInstance> instance;
    {
        Mutex::Autolock autoLock(mLock);
        if (mLiveNodes.size() == kMaxNodeInstances) {
            _hidl_cb(toStatus(NO_MEMORY), nullptr);
            return Void();
        }

    sp<OMXNodeInstance> instance = new OMXNodeInstance(
        instance = new OMXNodeInstance(
                this, new LWOmxObserver(observer), name.c_str());

        OMX_COMPONENTTYPE *handle;
@@ -128,8 +130,9 @@ Return<void> Omx::allocateNode(
        }

        mLiveNodes.add(observer.get(), instance);
    observer->linkToDeath(this, 0);
        mNode2Observer.add(instance.get(), observer.get());
    }
    observer->linkToDeath(this, 0);

    _hidl_cb(toStatus(OK), new TWOmxNode(instance));
    return Void();