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

Commit 230397ef authored by Jintao Zhu's avatar Jintao Zhu
Browse files

use sp<AudioEffect> instead of unique_ptr<AudioEffect>



As a child class of RefBase, an AudioEffect object should be held by sp<> rather than by unique_ptr<>.

If you use unique_ptr<> to hold it, then later, someone else, on the other hand, may probably use sp<> to hold it, then in the future, the AudioEffect object may be deleted two times: one is from sp<>, the other from unique_ptr<>.

This may be detected by the destructor of class RefBase, with the log complaint "RefBase: Explicit destruction,..."

Test: monkey test for one day and one night

Signed-off-by: default avatarJintao Zhu <zhujtcsieee@gmail.com>
Change-Id: I52e1df86899dfd8265aa80b4d3423936f66fcd47
parent 93aed30e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -970,7 +970,7 @@ void AudioPolicyEffects::initDefaultDeviceEffects()
    for (const auto& deviceEffectsIter : mDeviceEffects) {
        const auto& deviceEffects =  deviceEffectsIter.second;
        for (const auto& effectDesc : deviceEffects->mEffectDescriptors->mEffects) {
            auto fx = std::make_unique<AudioEffect>(String16("android"));
            sp<AudioEffect> fx = new AudioEffect(String16("android"));
            fx->set(EFFECT_UUID_NULL, &effectDesc->mUuid, 0, nullptr,
                    nullptr, AUDIO_SESSION_DEVICE, AUDIO_IO_HANDLE_NONE,
                    AudioDeviceTypeAddr{deviceEffects->getDeviceType(),
@@ -987,7 +987,7 @@ void AudioPolicyEffects::initDefaultDeviceEffects()
            ALOGV("%s(): create Fx %s added on port type=%d address=%s", __func__,
                  effectDesc->mName, deviceEffects->getDeviceType(),
                  deviceEffects->getDeviceAddress().c_str());
            deviceEffects->mEffects.push_back(std::move(fx));
            deviceEffects->mEffects.push_back(fx);
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -207,7 +207,7 @@ private:
            mDeviceType(device), mDeviceAddress(address) {}
        /*virtual*/ ~DeviceEffects() = default;

        std::vector<std::unique_ptr<AudioEffect>> mEffects;
        std::vector< sp<AudioEffect> > mEffects;
        audio_devices_t getDeviceType() const { return mDeviceType; }
        std::string getDeviceAddress() const { return mDeviceAddress; }
        const std::unique_ptr<EffectDescVector> mEffectDescriptors;