From 326430ecf08de0a00a7bdf0117bb123496ff7377 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Fri, 14 Mar 2025 09:06:24 +0100 Subject: [PATCH] MT#59962 CallLeg: `replaceExistingLeg()` use smart ptr Use smart pointers instead of handling with new/delete. Fixes: Resource leak (RESOURCE_LEAK) leaked_storage: Variable rev going out of scope leaks the storage it points to. Change-Id: I33dfe6c4a74a01774093dc500248c3ed613b5710 --- apps/sbc/CallLeg.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/sbc/CallLeg.cpp b/apps/sbc/CallLeg.cpp index c66081f2..f82cacbf 100644 --- a/apps/sbc/CallLeg.cpp +++ b/apps/sbc/CallLeg.cpp @@ -1552,11 +1552,14 @@ void CallLeg::replaceExistingLeg(const string &session_tag, const string &hdrs) } else b.media_session = NULL; - ReconnectLegEvent *rev = new ReconnectLegEvent(a_leg ? ReconnectLegEvent::B : ReconnectLegEvent::A, getLocalTag(), hdrs, dlg->established_body); + auto rev = std::make_unique(a_leg ? ReconnectLegEvent::B : ReconnectLegEvent::A, getLocalTag(), hdrs, dlg->established_body); + rev->setMedia(b.media_session, rtp_relay_mode); - ReplaceLegEvent *ev = new ReplaceLegEvent(getLocalTag(), rev); + + auto ev = std::make_unique(getLocalTag(), rev.release()); + // TODO: what about the RTP relay and other settings? send them as well? - if (!AmSessionContainer::instance()->postEvent(session_tag, ev)) { + if (!AmSessionContainer::instance()->postEvent(session_tag, ev.release())) { // session doesn't exist - can't connect ILOG_DLG(L_INFO, "the call leg to be replaced (%s) doesn't exist\n", session_tag.c_str()); if (b.media_session) {