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

Commit fed6db41 authored by Jon Spivack's avatar Jon Spivack
Browse files

Unregister Waiter in waitForService

IServiceManager's waitForService relies on notifications from servicemanager. Previously it registered with servicemanager but was missing an unregister call after use.

Bug: 144534962
Test: Manual (boot and dynamically start services)
Change-Id: Ic25349d42168a311e9fbce576f15de4067b0cc66
parent b5667012
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -280,6 +280,15 @@ sp<IBinder> ServiceManagerShim::waitForService(const String16& name16)
        std::condition_variable mCv;
    };

    // Simple RAII object to ensure a function call immediately before going out of scope
    class Defer {
    public:
        Defer(std::function<void()>&& f) : mF(std::move(f)) {}
        ~Defer() { mF(); }
    private:
        std::function<void()> mF;
    };

    const std::string name = String8(name16).c_str();

    sp<IBinder> out;
@@ -293,6 +302,9 @@ sp<IBinder> ServiceManagerShim::waitForService(const String16& name16)
            name, waiter).isOk()) {
        return nullptr;
    }
    Defer unregister ([&] {
        mTheRealServiceManager->unregisterForNotifications(name, waiter);
    });

    while(true) {
        {