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

Commit 3bcffa13 authored by Eric Laurent's avatar Eric Laurent
Browse files

force command flush after releasing a reference to shared memory

After releasing a reference to a shared memory interface,
IPCThreadState::self()->flushCommands() must be called to ensure
that the corresponding reference is also cleared immediately in the
remote process. Otherwise the binder implementaiton will not
push the clear systematically causing the memory region not to be freed.

See issues 10711502 and 2801375.

Bug: 14057166.
Change-Id: If55f36f00d452d6cf00cf83bd2fba1c8f3abcb57
parent 0ac53364
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -105,6 +105,8 @@ AudioRecord::~AudioRecord()
        }
        mAudioRecord->asBinder()->unlinkToDeath(mDeathNotifier, this);
        mAudioRecord.clear();
        mCblkMemory.clear();
        mBufferMemory.clear();
        IPCThreadState::self()->flushCommands();
        AudioSystem::releaseAudioSessionId(mSessionId, -1);
    }
@@ -546,9 +548,10 @@ status_t AudioRecord::openRecord_l(size_t epoch)
        mDeathNotifier.clear();
    }
    mAudioRecord = record;

    mCblkMemory = iMem;
    mBufferMemory = bufferMem;
    IPCThreadState::self()->flushCommands();

    mCblk = cblk;
    // note that temp is the (possibly revised) value of frameCount
    if (temp < frameCount || (frameCount == 0 && temp == 0)) {
+4 −1
Original line number Diff line number Diff line
@@ -174,6 +174,8 @@ AudioTrack::~AudioTrack()
        }
        mAudioTrack->asBinder()->unlinkToDeath(mDeathNotifier, this);
        mAudioTrack.clear();
        mCblkMemory.clear();
        mSharedBuffer.clear();
        IPCThreadState::self()->flushCommands();
        ALOGV("~AudioTrack, releasing session id from %d on behalf of %d",
                IPCThreadState::self()->getCallingPid(), mClientPid);
@@ -1059,8 +1061,9 @@ status_t AudioTrack::createTrack_l(size_t epoch)
        mDeathNotifier.clear();
    }
    mAudioTrack = track;

    mCblkMemory = iMem;
    IPCThreadState::self()->flushCommands();

    audio_track_cblk_t* cblk = static_cast<audio_track_cblk_t*>(iMemPointer);
    mCblk = cblk;
    // note that temp is the (possibly revised) value of frameCount
+2 −2
Original line number Diff line number Diff line
@@ -223,6 +223,8 @@ AudioFlinger::ThreadBase::TrackBase::~TrackBase()
        // relying on the automatic clear() at end of scope.
        mClient.clear();
    }
    // flush the binder command buffer
    IPCThreadState::self()->flushCommands();
}

// AudioBufferProvider interface
@@ -432,8 +434,6 @@ AudioFlinger::PlaybackThread::Track::~Track()
    // This prevents that leak.
    if (mSharedBuffer != 0) {
        mSharedBuffer.clear();
        // flush the binder command buffer
        IPCThreadState::self()->flushCommands();
    }
}