PatchTrackBase: fix null pointer dereference issue
cblk will be released when the function isTrackAllowed_l returns false, so when creating PatchTrackBase we should check whether the cblk is released to prevent null pointer dereferencing issue.
Test: make libaudioflinger
Bug: 290325983
Change-Id: I2a61b5b4f7777528cd4f8f2aa80dfec113bfce2e
Signed-off-by: gaoxiupei <gaoxiupei@xiaomi.corp-partner.google.com>
diff --git a/services/audioflinger/Tracks.cpp b/services/audioflinger/Tracks.cpp
index 5444c60..18c57ca 100644
--- a/services/audioflinger/Tracks.cpp
+++ b/services/audioflinger/Tracks.cpp
@@ -2186,7 +2186,8 @@
buffer, bufferSize, nullptr /* sharedBuffer */,
AUDIO_SESSION_NONE, getpid(), audioServerAttributionSource(getpid()), flags,
TYPE_PATCH, AUDIO_PORT_HANDLE_NONE, frameCountToBeReady),
- PatchTrackBase(new ClientProxy(mCblk, mBuffer, frameCount, mFrameSize, true, true),
+ PatchTrackBase(mCblk ? new ClientProxy(mCblk, mBuffer, frameCount, mFrameSize, true, true)
+ : nullptr,
*playbackThread, timeout)
{
ALOGV("%s(%d): sampleRate %d mPeerTimeout %d.%03d sec",
@@ -2766,7 +2767,8 @@
sampleRate, format, channelMask, frameCount,
buffer, bufferSize, AUDIO_SESSION_NONE, getpid(),
audioServerAttributionSource(getpid()), flags, TYPE_PATCH),
- PatchTrackBase(new ClientProxy(mCblk, mBuffer, frameCount, mFrameSize, false, true),
+ PatchTrackBase(mCblk ? new ClientProxy(mCblk, mBuffer, frameCount, mFrameSize, false, true)
+ : nullptr,
*recordThread, timeout)
{
ALOGV("%s(%d): sampleRate %d mPeerTimeout %d.%03d sec",