From 384f99be8ab4897929eb7cc9c3d5c1810446bc14 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Fri, 29 Sep 2017 10:56:10 +0200 Subject: [PATCH] Fix some memory leaks. --- src/conference/local-conference-event-handler.cpp | 2 +- src/conference/remote-conference-event-handler.cpp | 14 +++++++------- src/conference/remote-conference.cpp | 5 ++++- src/conference/session/call-session.cpp | 3 +-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/conference/local-conference-event-handler.cpp b/src/conference/local-conference-event-handler.cpp index 7e94fc45c..daaaba05b 100644 --- a/src/conference/local-conference-event-handler.cpp +++ b/src/conference/local-conference-event-handler.cpp @@ -49,7 +49,7 @@ void LocalConferenceEventHandlerPrivate::notifyFullState(string notify, Linphone linphone_content_set_buffer(content, notify.c_str(), strlen(notify.c_str())); linphone_event_notify(lev, content); linphone_content_unref(content); - // linphone_event_unref(lev); ?? + linphone_event_unref(lev); } void LocalConferenceEventHandlerPrivate::notifyAllExcept(string notify, const Address &addr) { diff --git a/src/conference/remote-conference-event-handler.cpp b/src/conference/remote-conference-event-handler.cpp index a24a5d947..94aa0abd4 100644 --- a/src/conference/remote-conference-event-handler.cpp +++ b/src/conference/remote-conference-event-handler.cpp @@ -51,10 +51,7 @@ RemoteConferenceEventHandler::RemoteConferenceEventHandler(LinphoneCore *core, C } RemoteConferenceEventHandler::~RemoteConferenceEventHandler() { - L_D(); xercesc::XMLPlatformUtils::Terminate(); - if (d->lev) - linphone_event_unref(d->lev); } // ----------------------------------------------------------------------------- @@ -65,16 +62,17 @@ void RemoteConferenceEventHandler::subscribe(const Address &addr) { LinphoneAddress *lAddr = linphone_address_new(d->confAddress.asString().c_str()); d->lev = linphone_core_create_subscribe(d->core, lAddr, "Conference", 600); linphone_address_unref(lAddr); - linphone_event_ref(d->lev); linphone_event_set_internal(d->lev, TRUE); linphone_event_set_user_data(d->lev, this); - linphone_event_add_custom_header(d->lev, "Conf-id", d->confAddress.getUsername().c_str()); // TODO : ??? linphone_event_send_subscribe(d->lev, nullptr); } void RemoteConferenceEventHandler::unsubscribe() { L_D(); - linphone_event_terminate(d->lev); + if (d->lev) { + linphone_event_terminate(d->lev); + d->lev = nullptr; + } } void RemoteConferenceEventHandler::notifyReceived(string xmlBody) { @@ -87,7 +85,9 @@ void RemoteConferenceEventHandler::notifyReceived(string xmlBody) { if (confInfo->getEntity() == cleanedConfAddress.asString()) { for (const auto &user : confInfo->getUsers()->getUser()) { LinphoneAddress *cAddr = linphone_core_interpret_url(d->core, user.getEntity()->c_str()); - Address addr(linphone_address_as_string(cAddr)); + char *cAddrStr = linphone_address_as_string(cAddr); + Address addr(cAddrStr); + bctbx_free(cAddrStr); if (user.getState() == "deleted") d->listener->onParticipantRemoved(addr); else { diff --git a/src/conference/remote-conference.cpp b/src/conference/remote-conference.cpp index 2200d417d..f83f10e67 100644 --- a/src/conference/remote-conference.cpp +++ b/src/conference/remote-conference.cpp @@ -33,6 +33,7 @@ RemoteConference::RemoteConference (LinphoneCore *core, const Address &myAddress } RemoteConference::~RemoteConference () { + eventHandler->unsubscribe(); delete eventHandler; } @@ -81,7 +82,9 @@ string RemoteConference::getResourceLists (const list
&addresses) { void RemoteConference::onConferenceCreated (const Address &addr) {} -void RemoteConference::onConferenceTerminated (const Address &addr) {} +void RemoteConference::onConferenceTerminated (const Address &addr) { + eventHandler->unsubscribe(); +} void RemoteConference::onParticipantAdded (const Address &addr) {} diff --git a/src/conference/session/call-session.cpp b/src/conference/session/call-session.cpp index 01bac32d6..5dd173e5d 100644 --- a/src/conference/session/call-session.cpp +++ b/src/conference/session/call-session.cpp @@ -600,9 +600,8 @@ void CallSessionPrivate::setContactOp () { LinphoneAddress *contact = getFixedContact(); if (contact) { salAddress = const_cast(L_GET_PRIVATE_FROM_C_OBJECT(contact)->getInternalAddress()); - sal_address_ref(salAddress); - linphone_address_unref(contact); sal_op_set_contact_address(op, salAddress); + linphone_address_unref(contact); } }