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

Commit 02d67d52 authored by Marco Nelissen's avatar Marco Nelissen Committed by Android Git Automerger
Browse files

am 277090f1: Merge "Fix potential deadlock in unregisterStaleHandlers()" into lmp-dev

* commit '277090f1':
  Fix potential deadlock in unregisterStaleHandlers()
parents 1b6d6789 277090f1
Loading
Loading
Loading
Loading
+19 −7
Original line number Diff line number Diff line
@@ -72,6 +72,9 @@ void ALooperRoster::unregisterHandler(ALooper::handler_id handlerID) {
}

void ALooperRoster::unregisterStaleHandlers() {

    Vector<sp<ALooper> > activeLoopers;
    {
        Mutex::Autolock autoLock(mLock);

        for (size_t i = mHandlers.size(); i-- > 0;) {
@@ -81,6 +84,15 @@ void ALooperRoster::unregisterStaleHandlers() {
            if (looper == NULL) {
                ALOGV("Unregistering stale handler %d", mHandlers.keyAt(i));
                mHandlers.removeItemsAt(i);
            } else {
                // At this point 'looper' might be the only sp<> keeping
                // the object alive. To prevent it from going out of scope
                // and having ~ALooper call this method again recursively
                // and then deadlocking because of the Autolock above, add
                // it to a Vector which will go out of scope after the lock
                // has been released.
                activeLoopers.add(looper);
            }
        }
    }
}