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

Commit 9b3359fe authored by Haynes Mathew George's avatar Haynes Mathew George Committed by Glenn Kasten
Browse files

libmedia: Initialize state vars to avoid possible crash



If playback or record track creation fails on server side,
some state is left initialized incorrectly.
This can cause a crash when the object is destroyed
because of a reference to a NULL object.

Initialize state vars properly in the initialization list
to avoid this behavior.

authored-by: default avatarZhou Song <zhous@codeaurora.org>

CRs-Fixed: 992608
Change-Id: If8c3611e3229c0c1b14b81285e07b9357fec7658
parent 15ac558b
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ status_t AudioRecord::getMinFrameCount(
// ---------------------------------------------------------------------------

AudioRecord::AudioRecord(const String16 &opPackageName)
    : mStatus(NO_INIT), mOpPackageName(opPackageName), mSessionId(AUDIO_SESSION_ALLOCATE),
    : mActive(false), mStatus(NO_INIT), mOpPackageName(opPackageName), mSessionId(AUDIO_SESSION_ALLOCATE),
      mPreviousPriority(ANDROID_PRIORITY_NORMAL), mPreviousSchedulingGroup(SP_DEFAULT),
      mSelectedDeviceId(AUDIO_PORT_HANDLE_NONE)
{
@@ -88,7 +88,8 @@ AudioRecord::AudioRecord(
        int uid,
        pid_t pid,
        const audio_attributes_t* pAttributes)
    : mStatus(NO_INIT),
    : mActive(false),
      mStatus(NO_INIT),
      mOpPackageName(opPackageName),
      mSessionId(AUDIO_SESSION_ALLOCATE),
      mPreviousPriority(ANDROID_PRIORITY_NORMAL),
@@ -268,7 +269,6 @@ status_t AudioRecord::set(
    }

    mStatus = NO_ERROR;
    mActive = false;
    mUserData = user;
    // TODO: add audio hardware input latency here
    mLatency = (1000 * mFrameCount) / mSampleRate;
+3 −1
Original line number Diff line number Diff line
@@ -163,6 +163,7 @@ status_t AudioTrack::getMinFrameCount(

AudioTrack::AudioTrack()
    : mStatus(NO_INIT),
      mState(STATE_STOPPED),
      mPreviousPriority(ANDROID_PRIORITY_NORMAL),
      mPreviousSchedulingGroup(SP_DEFAULT),
      mPausedPosition(0),
@@ -192,6 +193,7 @@ AudioTrack::AudioTrack(
        const audio_attributes_t* pAttributes,
        bool doNotReconnect)
    : mStatus(NO_INIT),
      mState(STATE_STOPPED),
      mPreviousPriority(ANDROID_PRIORITY_NORMAL),
      mPreviousSchedulingGroup(SP_DEFAULT),
      mPausedPosition(0),
@@ -221,6 +223,7 @@ AudioTrack::AudioTrack(
        const audio_attributes_t* pAttributes,
        bool doNotReconnect)
    : mStatus(NO_INIT),
      mState(STATE_STOPPED),
      mPreviousPriority(ANDROID_PRIORITY_NORMAL),
      mPreviousSchedulingGroup(SP_DEFAULT),
      mPausedPosition(0),
@@ -477,7 +480,6 @@ status_t AudioTrack::set(
    }

    mStatus = NO_ERROR;
    mState = STATE_STOPPED;
    mUserData = user;
    mLoopCount = 0;
    mLoopStart = 0;