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

Commit 277090f1 authored by Marco Nelissen's avatar Marco Nelissen Committed by Android (Google) Code Review
Browse files

Merge "Fix potential deadlock in unregisterStaleHandlers()" into lmp-dev

parents d362ea17 75c672fc
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);
            }
        }
    }
}