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

Commit c1a06b44 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix FilterClientCallbackImpl race condition" into main

parents 931fe7cc 03c3d6bc
Loading
Loading
Loading
Loading
+19 −7
Original line number Diff line number Diff line
@@ -701,6 +701,9 @@ void FilterClientCallbackImpl::getMediaEvent(const jobjectArray& arr, const int

    // Protect mFilterClient from being set to null.
    android::Mutex::Autolock autoLock(mLock);
    if (mFilterClient == nullptr) {
        return;
    }
    uint64_t avSharedMemSize = mFilterClient->getAvSharedHandleInfo().size;
    if (mediaEvent.avMemory.fds.size() > 0 || mediaEvent.avDataId != 0 ||
        (dataLength > 0 && (dataLength + offset) < avSharedMemSize)) {
@@ -868,10 +871,18 @@ void FilterClientCallbackImpl::getRestartEvent(const jobjectArray& arr, const in
void FilterClientCallbackImpl::onFilterEvent(const vector<DemuxFilterEvent> &events) {
    ALOGV("FilterClientCallbackImpl::onFilterEvent");
    JNIEnv *env = AndroidRuntime::getJNIEnv();

    ScopedLocalRef<jobjectArray> array(env);

    if (!events.empty()) {
        array.reset(env->NewObjectArray(events.size(), mEventClass, nullptr));
        if (env->IsSameObject(array.get(), nullptr)) {
            // It can happen when FilterClientCallbackImpl release the resource
            // in another thread.
            ALOGE("FilterClientCallbackImpl::onFilterEvent:"
                  "Unable to create object array of filter events. Ignoring callback.");
            return;
        }
    }

    for (int i = 0, arraySize = 0; i < events.size(); i++) {
@@ -1070,14 +1081,15 @@ FilterClientCallbackImpl::FilterClientCallbackImpl() {

FilterClientCallbackImpl::~FilterClientCallbackImpl() {
    JNIEnv *env = AndroidRuntime::getJNIEnv();
    {

    android::Mutex::Autolock autoLock(mLock);

    if (mFilterObj != nullptr) {
        env->DeleteWeakGlobalRef(mFilterObj);
        mFilterObj = nullptr;
    }
    mFilterClient = nullptr;
    }

    env->DeleteGlobalRef(mEventClass);
    env->DeleteGlobalRef(mSectionEventClass);
    env->DeleteGlobalRef(mMediaEventClass);