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

Commit 5e94634d authored by Tom Murphy's avatar Tom Murphy
Browse files

Fix race condition in extension string creation

Change a1742966 introduced a race condition where the notfiy_all is called before the mExtensionString is set.
Set mExtensionString before refCond.notify_all(); is called

Bug: 345419965
Bug: 346881664
Test: Ran EGL unit tests
Change-Id: Ifcb691f9b9769be494e204c97512c3f7fffec60a
parent c9e99f79
Loading
Loading
Loading
Loading
+8 −8
Original line number Original line Diff line number Diff line
@@ -383,14 +383,6 @@ EGLBoolean egl_display_t::initialize(EGLint* major, EGLint* minor) {
        // before using cnx->major & cnx->minor
        // before using cnx->major & cnx->minor
        if (major != nullptr) *major = cnx->major;
        if (major != nullptr) *major = cnx->major;
        if (minor != nullptr) *minor = cnx->minor;
        if (minor != nullptr) *minor = cnx->minor;
    }

    { // scope for refLock
        std::unique_lock<std::mutex> _l(refLock);
        eglIsInitialized = true;
        refCond.notify_all();
    }

        auto mergeExtensionStrings = [](const std::vector<std::string>& strings) {
        auto mergeExtensionStrings = [](const std::vector<std::string>& strings) {
            std::ostringstream combinedStringStream;
            std::ostringstream combinedStringStream;
            std::copy(strings.begin(), strings.end(),
            std::copy(strings.begin(), strings.end(),
@@ -399,6 +391,14 @@ EGLBoolean egl_display_t::initialize(EGLint* major, EGLint* minor) {
            return gBuiltinExtensionString + combinedStringStream.str();
            return gBuiltinExtensionString + combinedStringStream.str();
        };
        };
        mExtensionString = mergeExtensionStrings(extensionStrings);
        mExtensionString = mergeExtensionStrings(extensionStrings);
    }

    { // scope for refLock
        std::unique_lock<std::mutex> _l(refLock);
        eglIsInitialized = true;
        refCond.notify_all();
    }

    return EGL_TRUE;
    return EGL_TRUE;
}
}