From 575069db123d2224b4359d63273808e78e1efa3f Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Mon, 14 May 2018 16:00:15 +0200 Subject: [PATCH] Correctly handle LinphoneEvent object and unsubscribe correctly for client group chat rooms that do not use list subscription. --- src/chat/chat-room/client-group-chat-room.cpp | 4 ++-- .../handlers/remote-conference-event-handler.cpp | 6 ++---- .../remote-conference-list-event-handler.cpp | 15 ++++++--------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/chat/chat-room/client-group-chat-room.cpp b/src/chat/chat-room/client-group-chat-room.cpp index c7ee9d6fa..fbad53fed 100644 --- a/src/chat/chat-room/client-group-chat-room.cpp +++ b/src/chat/chat-room/client-group-chat-room.cpp @@ -523,7 +523,7 @@ void ClientGroupChatRoom::leave () { L_D(); L_D_T(RemoteConference, dConference); - dConference->eventHandler->getPrivate()->lev = nullptr; + dConference->eventHandler->unsubscribe(); shared_ptr session = dConference->focus->getPrivate()->getSession(); if (session) session->terminate(); @@ -559,7 +559,7 @@ void ClientGroupChatRoom::onConferenceTerminated (const IdentityAddress &addr) { L_D(); L_D_T(RemoteConference, dConference); - dConference->eventHandler->getPrivate()->lev = nullptr; + dConference->eventHandler->unsubscribe(); dConference->eventHandler->resetLastNotify(); d->setState(ChatRoom::State::Terminated); d->addEvent(make_shared( diff --git a/src/conference/handlers/remote-conference-event-handler.cpp b/src/conference/handlers/remote-conference-event-handler.cpp index 015b0f071..69142d6f3 100644 --- a/src/conference/handlers/remote-conference-event-handler.cpp +++ b/src/conference/handlers/remote-conference-event-handler.cpp @@ -208,7 +208,7 @@ void RemoteConferenceEventHandlerPrivate::subscribe () { return; } - lev = linphone_event_ref(linphone_core_create_subscribe(conf->getCore()->getCCore(), lAddr, "conference", 600)); + lev = linphone_core_create_subscribe(conf->getCore()->getCCore(), lAddr, "conference", 600); lev->op->setFrom(chatRoomId.getLocalAddress().asString().c_str()); const string &lastNotifyStr = Utils::toString(lastNotify); linphone_event_add_custom_header(lev, "Last-Notify-Version", lastNotifyStr.c_str()); @@ -222,7 +222,6 @@ void RemoteConferenceEventHandlerPrivate::subscribe () { void RemoteConferenceEventHandlerPrivate::unsubscribe () { if (lev) { linphone_event_terminate(lev); - linphone_event_unref(lev); lev = nullptr; } } @@ -257,8 +256,7 @@ RemoteConferenceEventHandler::~RemoteConferenceEventHandler () { // Unable to unregister listener here. Core is destroyed and the listener doesn't exist. } - if (d->lev) - unsubscribe(); + unsubscribe(); } // ----------------------------------------------------------------------------- diff --git a/src/conference/handlers/remote-conference-list-event-handler.cpp b/src/conference/handlers/remote-conference-list-event-handler.cpp index 32e07be7c..fa4e2e89b 100644 --- a/src/conference/handlers/remote-conference-list-event-handler.cpp +++ b/src/conference/handlers/remote-conference-list-event-handler.cpp @@ -57,8 +57,7 @@ RemoteConferenceListEventHandler::~RemoteConferenceListEventHandler () { // Unable to unregister listener here. Core is destroyed and the listener doesn't exist. } - if (lev) - unsubscribe(); + unsubscribe(); } // ----------------------------------------------------------------------------- @@ -105,7 +104,7 @@ void RemoteConferenceListEventHandler::subscribe () { LinphoneAddress *rlsAddr = linphone_address_new(linphone_proxy_config_get_conference_factory_uri(cfg)); - lev = linphone_event_ref(linphone_core_create_subscribe(lc, rlsAddr, "conference", 600)); + lev = linphone_core_create_subscribe(lc, rlsAddr, "conference", 600); char *from = linphone_address_as_string(linphone_proxy_config_get_contact(linphone_core_get_default_proxy_config(getCore()->getCCore()))); lev->op->setFrom(from); bctbx_free(from); @@ -126,12 +125,10 @@ void RemoteConferenceListEventHandler::subscribe () { } void RemoteConferenceListEventHandler::unsubscribe () { - if (!lev) - return; - - linphone_event_terminate(lev); - linphone_event_unref(lev); - lev = nullptr; + if (lev) { + linphone_event_terminate(lev); + lev = nullptr; + } } void RemoteConferenceListEventHandler::notifyReceived (const Content *notifyContent) {