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

Commit 172938d1 authored by Andy Hung's avatar Andy Hung
Browse files

EffectBundle: Fix sessionNo allocation

Fixes duplicate sessionNo for the same sessionId which
causes crashes, effect glitching, and random failure.

Test: Solo Tester long run
Bug: 70809793
Change-Id: I872635641f5a0794cb7792bf80c3eac0661f0180
parent 9bbba136
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -189,7 +189,7 @@ extern "C" int EffectCreate(const effect_uuid_t *uuid,
                            int32_t             ioId __unused,
                            effect_handle_t  *pHandle){
    int ret = 0;
    int sessionNo;
    int sessionNo = -1;
    int i;
    EffectContext *pContext = NULL;
    bool newBundle = false;
@@ -209,22 +209,27 @@ extern "C" int EffectCreate(const effect_uuid_t *uuid,
        LvmGlobalBundle_init();
    }

    // Find next available sessionNo
    // Find sessionNo: if one already exists for the sessionId use it,
    // otherwise choose the first available empty slot.
    for(i=0; i<LVM_MAX_SESSIONS; i++){
        if((SessionIndex[i] == LVM_UNUSED_SESSION)||(SessionIndex[i] == sessionId)){
        if (SessionIndex[i] == sessionId) {
            sessionNo = i;
            SessionIndex[i] = sessionId;
            ALOGV("\tEffectCreate: Allocating SessionNo %d for SessionId %d\n", sessionNo,sessionId);
            break;
        }
        if (sessionNo < 0 && SessionIndex[i] == LVM_UNUSED_SESSION) {
            sessionNo = i;
            // do not break; allow loop to continue to search for a sessionId match.
        }

    if(i==LVM_MAX_SESSIONS){
    }
    if (sessionNo < 0) {
        ALOGV("\tLVM_ERROR : Cannot find memory to allocate for current session");
        ret = -EINVAL;
        goto exit;
    }

    SessionIndex[sessionNo] = sessionId;
    ALOGV("\tEffectCreate: Allocating sessionNo %d for sessionId %d\n", sessionNo, sessionId);

    pContext = new EffectContext;

    // If this is the first create in this session