From 63b08b7ebff1552c7bba234dbddaf36a523bcfe1 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Mon, 19 Mar 2018 16:00:01 +0100 Subject: [PATCH] fix crash on core destruction --- src/chat/chat-room/client-group-chat-room.cpp | 5 ++++- .../chat-room/server-group-chat-room-stub.cpp | 6 ++++-- src/chat/chat-room/server-group-chat-room.h | 2 ++ .../local-conference-list-event-handler.cpp | 16 +++++++++++----- .../local-conference-list-event-handler.h | 9 +++++---- .../remote-conference-list-event-handler.cpp | 16 +++++++++++----- .../remote-conference-list-event-handler.h | 9 +++++---- src/core/core.cpp | 3 +++ 8 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/chat/chat-room/client-group-chat-room.cpp b/src/chat/chat-room/client-group-chat-room.cpp index 965293a3f..e1a9e2846 100644 --- a/src/chat/chat-room/client-group-chat-room.cpp +++ b/src/chat/chat-room/client-group-chat-room.cpp @@ -218,11 +218,14 @@ RemoteConference(core, me->getAddress(), nullptr) { dConference->eventHandler->setChatRoomId(chatRoomId); dConference->eventHandler->setLastNotify(lastNotifyId); - getCore()->getPrivate()->remoteListEventHandler->addHandler(dConference->eventHandler); + getCore()->getPrivate()->remoteListEventHandler->addHandler(dConference->eventHandler.get()); } ClientGroupChatRoom::~ClientGroupChatRoom () { L_D(); + L_D_T(RemoteConference, dConference); + + getCore()->getPrivate()->remoteListEventHandler->removeHandler(dConference->eventHandler.get()); d->setCallSessionListener(nullptr); } diff --git a/src/chat/chat-room/server-group-chat-room-stub.cpp b/src/chat/chat-room/server-group-chat-room-stub.cpp index ad0ce75f6..d97622101 100644 --- a/src/chat/chat-room/server-group-chat-room-stub.cpp +++ b/src/chat/chat-room/server-group-chat-room-stub.cpp @@ -149,16 +149,18 @@ ServerGroupChatRoom::ServerGroupChatRoom ( ) : ChatRoom(*new ServerGroupChatRoomPrivate, core, ChatRoomId(peerAddress, peerAddress)), LocalConference(core, peerAddress, nullptr) {} +ServerGroupChatRoom::~ServerGroupChatRoom () {}; + ServerGroupChatRoom::CapabilitiesMask ServerGroupChatRoom::getCapabilities () const { return 0; } void ServerGroupChatRoom::allowCpim (bool value) { - + } void ServerGroupChatRoom::allowMultipart (bool value) { - + } bool ServerGroupChatRoom::canHandleCpim () const { diff --git a/src/chat/chat-room/server-group-chat-room.h b/src/chat/chat-room/server-group-chat-room.h index 57d49dcfc..d84ba8341 100644 --- a/src/chat/chat-room/server-group-chat-room.h +++ b/src/chat/chat-room/server-group-chat-room.h @@ -45,6 +45,8 @@ public: unsigned int lastNotifyId ); + ~ServerGroupChatRoom (); + std::shared_ptr getCore () const; void allowCpim (bool value) override; diff --git a/src/conference/handlers/local-conference-list-event-handler.cpp b/src/conference/handlers/local-conference-list-event-handler.cpp index d6eb2cb28..95014e8d1 100644 --- a/src/conference/handlers/local-conference-list-event-handler.cpp +++ b/src/conference/handlers/local-conference-list-event-handler.cpp @@ -86,7 +86,7 @@ void LocalConferenceListEventHandler::subscribeReceived (LinphoneEvent *lev, con addr.removeUriParam("Last-Notify"); int notifyId = notifyIdStr.empty() ? 0 : Utils::stoi(notifyIdStr); ChatRoomId chatRoomId(addr, addr); - shared_ptr handler = findHandler(chatRoomId); + LocalConferenceEventHandler *handler = findHandler(chatRoomId); if (!handler) continue; @@ -154,11 +154,17 @@ void LocalConferenceListEventHandler::subscribeReceived (LinphoneEvent *lev, con // ----------------------------------------------------------------------------- -void LocalConferenceListEventHandler::addHandler (shared_ptr handler) { - handlers.push_back(handler); +void LocalConferenceListEventHandler::addHandler (LocalConferenceEventHandler *handler) { + if (handler) + handlers.push_back(handler); } -shared_ptr LocalConferenceListEventHandler::findHandler (const ChatRoomId &chatRoomId) const { +void LocalConferenceListEventHandler::removeHandler (LocalConferenceEventHandler *handler) { + if (handler) + handlers.remove(handler); +} + +LocalConferenceEventHandler *LocalConferenceListEventHandler::findHandler (const ChatRoomId &chatRoomId) const { for (const auto &handler : handlers) { if (handler->getChatRoomId() == chatRoomId) return handler; @@ -167,7 +173,7 @@ shared_ptr LocalConferenceListEventHandler::findHan return nullptr; } -const list> &LocalConferenceListEventHandler::getHandlers () const { +const list &LocalConferenceListEventHandler::getHandlers () const { return handlers; } diff --git a/src/conference/handlers/local-conference-list-event-handler.h b/src/conference/handlers/local-conference-list-event-handler.h index 0240fb615..62dbfe887 100644 --- a/src/conference/handlers/local-conference-list-event-handler.h +++ b/src/conference/handlers/local-conference-list-event-handler.h @@ -38,12 +38,13 @@ class LocalConferenceEventHandler; class LocalConferenceListEventHandler { public: void subscribeReceived (LinphoneEvent *lev, const LinphoneContent *body); - void addHandler (std::shared_ptr handler); - std::shared_ptr findHandler (const ChatRoomId &chatRoomId) const; - const std::list> &getHandlers () const; + void addHandler (LocalConferenceEventHandler *handler); + void removeHandler (LocalConferenceEventHandler *handler); + LocalConferenceEventHandler *findHandler (const ChatRoomId &chatRoomId) const; + const std::list &getHandlers () const; private: - std::list> handlers; + std::list handlers; }; diff --git a/src/conference/handlers/remote-conference-list-event-handler.cpp b/src/conference/handlers/remote-conference-list-event-handler.cpp index 011bedaef..ea619757a 100644 --- a/src/conference/handlers/remote-conference-list-event-handler.cpp +++ b/src/conference/handlers/remote-conference-list-event-handler.cpp @@ -142,7 +142,7 @@ void RemoteConferenceListEventHandler::notifyReceived (Content *multipart) { Address cid(value); Address peer = addresses[cid]; ChatRoomId id(local, peer); - shared_ptr handler = findHandler(id); + RemoteConferenceEventHandler *handler = findHandler(id); if (!handler) continue; @@ -155,7 +155,7 @@ void RemoteConferenceListEventHandler::notifyReceived (Content *multipart) { // ----------------------------------------------------------------------------- -shared_ptr RemoteConferenceListEventHandler::findHandler (const ChatRoomId &chatRoomId) const { +RemoteConferenceEventHandler *RemoteConferenceListEventHandler::findHandler (const ChatRoomId &chatRoomId) const { for (const auto &handler : handlers) { if (handler->getChatRoomId() == chatRoomId) return handler; @@ -164,12 +164,18 @@ shared_ptr RemoteConferenceListEventHandler::findH return nullptr; } -const list> &RemoteConferenceListEventHandler::getHandlers () const { +const list &RemoteConferenceListEventHandler::getHandlers () const { return handlers; } -void RemoteConferenceListEventHandler::addHandler (std::shared_ptr handler) { - handlers.push_back(handler); +void RemoteConferenceListEventHandler::addHandler (RemoteConferenceEventHandler *handler) { + if (handler) + handlers.push_back(handler); +} + +void RemoteConferenceListEventHandler::removeHandler (RemoteConferenceEventHandler *handler) { + if (handler) + handlers.remove(handler); } map RemoteConferenceListEventHandler::parseRlmi (const string &xmlBody) const { diff --git a/src/conference/handlers/remote-conference-list-event-handler.h b/src/conference/handlers/remote-conference-list-event-handler.h index 6b606c305..53bf78e60 100644 --- a/src/conference/handlers/remote-conference-list-event-handler.h +++ b/src/conference/handlers/remote-conference-list-event-handler.h @@ -47,12 +47,13 @@ public: void subscribe (); void unsubscribe (); void notifyReceived (Content *multipart); - void addHandler (std::shared_ptr handler); - std::shared_ptr findHandler (const ChatRoomId &chatRoomId) const; - const std::list> &getHandlers () const; + void addHandler (RemoteConferenceEventHandler *handler); + void removeHandler (RemoteConferenceEventHandler *handler); + RemoteConferenceEventHandler *findHandler (const ChatRoomId &chatRoomId) const; + const std::list &getHandlers () const; private: - std::list> handlers; + std::list handlers; LinphoneEvent *lev = nullptr; std::map parseRlmi (const std::string &xmlBody) const; diff --git a/src/core/core.cpp b/src/core/core.cpp index 4a2bc9225..d3e8be1c2 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -87,6 +87,9 @@ void CorePrivate::uninit () { chatRoomsById.clear(); noCreatedClientGroupChatRooms.clear(); + remoteListEventHandler = nullptr; + localListEventHandler = nullptr; + AddressPrivate::clearSipAddressesCache(); }