Fix AudioTrack shared memory leak
Bug: 2801375
Change-Id: I50e15164fe310f69ea019dca5b49171a02bc6992
diff --git a/services/audioflinger/Tracks.cpp b/services/audioflinger/Tracks.cpp
index 6002aa3..cd54950 100644
--- a/services/audioflinger/Tracks.cpp
+++ b/services/audioflinger/Tracks.cpp
@@ -364,6 +364,16 @@
AudioFlinger::PlaybackThread::Track::~Track()
{
ALOGV("PlaybackThread::Track destructor");
+
+ // The destructor would clear mSharedBuffer,
+ // but it will not push the decremented reference count,
+ // leaving the client's IMemory dangling indefinitely.
+ // This prevents that leak.
+ if (mSharedBuffer != 0) {
+ mSharedBuffer.clear();
+ // flush the binder command buffer
+ IPCThreadState::self()->flushCommands();
+ }
}
void AudioFlinger::PlaybackThread::Track::destroy()