From f3990f2cc8fd824ae52a880a7b22248e1bdfb192 Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Tue, 13 Dec 2011 11:50:00 -0800 Subject: [PATCH] Improve resistance to leaks for ConfigEvent A Vector of pointers is risky, as there is no ownership (and the ThreadBase destructor was not deleting them, so if there were any left over at end it would leak). Replaced by a Vector of values. Change-Id: Iddde72dc30134adfcf724dec26cbe0a742509b8c --- services/audioflinger/AudioFlinger.cpp | 13 ++++++------- services/audioflinger/AudioFlinger.h | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index b48f23d900..39f95bbf87 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -1062,9 +1062,9 @@ void AudioFlinger::ThreadBase::sendConfigEvent(int event, int param) // sendConfigEvent_l() must be called with ThreadBase::mLock held void AudioFlinger::ThreadBase::sendConfigEvent_l(int event, int param) { - ConfigEvent *configEvent = new ConfigEvent(); - configEvent->mEvent = event; - configEvent->mParam = param; + ConfigEvent configEvent; + configEvent.mEvent = event; + configEvent.mParam = param; mConfigEvents.add(configEvent); ALOGV("sendConfigEvent() num events %d event %d, param %d", mConfigEvents.size(), event, param); mWaitWorkCV.signal(); @@ -1075,15 +1075,14 @@ void AudioFlinger::ThreadBase::processConfigEvents() mLock.lock(); while(!mConfigEvents.isEmpty()) { ALOGV("processConfigEvents() remaining events %d", mConfigEvents.size()); - ConfigEvent *configEvent = mConfigEvents[0]; + ConfigEvent configEvent = mConfigEvents[0]; mConfigEvents.removeAt(0); // release mLock before locking AudioFlinger mLock: lock order is always // AudioFlinger then ThreadBase to avoid cross deadlock mLock.unlock(); mAudioFlinger->mLock.lock(); - audioConfigChanged_l(configEvent->mEvent, configEvent->mParam); + audioConfigChanged_l(configEvent.mEvent, configEvent.mParam); mAudioFlinger->mLock.unlock(); - delete configEvent; mLock.lock(); } mLock.unlock(); @@ -1130,7 +1129,7 @@ status_t AudioFlinger::ThreadBase::dumpBase(int fd, const Vector& args snprintf(buffer, SIZE, " Index event param\n"); result.append(buffer); for (size_t i = 0; i < mConfigEvents.size(); i++) { - snprintf(buffer, SIZE, " %02d %02d %d\n", i, mConfigEvents[i]->mEvent, mConfigEvents[i]->mParam); + snprintf(buffer, SIZE, " %02d %02d %d\n", i, mConfigEvents[i].mEvent, mConfigEvents[i].mParam); result.append(buffer); } result.append("\n"); diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h index 6cafa7ef7e..25c60c760f 100644 --- a/services/audioflinger/AudioFlinger.h +++ b/services/audioflinger/AudioFlinger.h @@ -547,7 +547,7 @@ private: Condition mParamCond; Vector mNewParameters; status_t mParamStatus; - Vector mConfigEvents; + Vector mConfigEvents; bool mStandby; int mId; bool mExiting; -- 2.11.0