From a1a7eec0ea28302aae9c77620244bed051f16d6a Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Tue, 19 May 2026 21:41:25 +0200 Subject: [PATCH] MT#59962 AmSession: use lock guards for `audio_mut` In some of the usages of manual lock/unlock, an exception can leave the mutex locked. So the guard should fit this better. Change-Id: I3541abe7a0ec63edffe1e180c691531cabb3fccd --- core/AmSession.cpp | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/core/AmSession.cpp b/core/AmSession.cpp index a12d64a8..7f1db1b5 100644 --- a/core/AmSession.cpp +++ b/core/AmSession.cpp @@ -232,31 +232,27 @@ void AmSession::addHandler(AmSessionEventHandler* sess_evh) void AmSession::setInput(AmAudio* in) { - lockAudio(); + lock_guard lock(audio_mut); input = in; - unlockAudio(); } void AmSession::setOutput(AmAudio* out) { - lockAudio(); + lock_guard lock(audio_mut); output = out; - unlockAudio(); } void AmSession::setInOut(AmAudio* in,AmAudio* out) { - lockAudio(); + lock_guard lock(audio_mut); input = in; output = out; - unlockAudio(); } bool AmSession::isAudioSet() { - lockAudio(); + lock_guard lock(audio_mut); bool set = input || output; - unlockAudio(); return set; } @@ -711,7 +707,7 @@ void AmSession::onDtmf(int event, int duration_msec) void AmSession::clearAudio() { - lockAudio(); + lock_guard lock(audio_mut); if (input) { input->close(); @@ -722,7 +718,6 @@ void AmSession::clearAudio() output = NULL; } - unlockAudio(); ILOG_DLG(L_DBG, "Audio cleared !!!\n"); postEvent(new AmAudioEvent(AmAudioEvent::cleared)); } @@ -1145,7 +1140,7 @@ int AmSession::onSdpCompleted(const AmSdp& local_sdp, const AmSdp& remote_sdp) // set_on_hold = pos != remote_sdp.media[0].attributes.end(); // } - lockAudio(); + lock_guard lock(audio_mut); // set active RTP stream to the one with proper transport for (vector::const_iterator m_it = remote_sdp.media.begin(); @@ -1178,7 +1173,6 @@ int AmSession::onSdpCompleted(const AmSdp& local_sdp, const AmSdp& remote_sdp) ILOG_DLG(L_ERR, "Error while initializing RTP stream (unknown exception in AmRTPStream::init)\n"); ret = -1; } - unlockAudio(); if (!isProcessingMedia()) { setInbandDetector(AmConfig::DefaultDTMFDetector); @@ -1292,12 +1286,12 @@ int AmSession::sendInvite(const string& headers) void AmSession::setOnHold(bool hold) { - lockAudio(); + lock_guard lock(audio_mut); + bool old_hold = RTPStream()->getOnHold(); RTPStream()->setOnHold(hold); if (hold != old_hold) sendReinvite(); - unlockAudio(); } int AmSession::getRtpInterface() @@ -1403,7 +1397,7 @@ bool AmSession::removeTimers() { int AmSession::readStreams(unsigned long long ts, unsigned char *buffer) { int res = 0; - lockAudio(); + lock_guard lock(audio_mut); AmRtpAudio *stream = RTPStream(); unsigned int f_size = stream->getFrameSize(); @@ -1422,14 +1416,13 @@ int AmSession::readStreams(unsigned long long ts, unsigned char *buffer) } } - unlockAudio(); return res; } int AmSession::writeStreams(unsigned long long ts, unsigned char *buffer) { int res = 0; - lockAudio(); + lock_guard lock(audio_mut); AmRtpAudio *stream = RTPStream(); if (stream->sendIntReached()) { // FIXME: shouldn't depend on checkInterval call before! @@ -1443,7 +1436,6 @@ int AmSession::writeStreams(unsigned long long ts, unsigned char *buffer) res = stream->put(ts, buffer, stream->getSampleRate(), got); } - unlockAudio(); return res; }