From 672ae55ea6888f5afffcb6d8ec789054ececd304 Mon Sep 17 00:00:00 2001 From: Gaelle Braud Date: Thu, 22 May 2025 09:50:28 +0200 Subject: [PATCH] try to fix read access violation (Mantis 0013842) --- Linphone/model/search/MagicSearchModel.cpp | 20 +++++++++++-------- Linphone/model/tool/ToolModel.cpp | 3 ++- .../Display/Chat/ChatMessagesListView.qml | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Linphone/model/search/MagicSearchModel.cpp b/Linphone/model/search/MagicSearchModel.cpp index 83d2d98c3..5d8b868a4 100644 --- a/Linphone/model/search/MagicSearchModel.cpp +++ b/Linphone/model/search/MagicSearchModel.cpp @@ -83,15 +83,19 @@ void MagicSearchModel::onSearchResultsReceived(const std::shared_ptrgetFriend(); auto friendsManager = FriendsManager::getInstance(); if (f) { qDebug() << "friend exists, append to unknown map"; - auto friendAddress = f->getAddress()->clone(); - friendAddress->clean(); - friendsManager->appendUnknownFriend(friendAddress, f); - if (friendsManager->isInOtherAddresses(Utils::coreStringToAppString(friendAddress->asStringUriOnly()))) { - friendsManager->removeOtherAddress(Utils::coreStringToAppString(friendAddress->asStringUriOnly())); + auto friendAddress = f->getAddress() ? f->getAddress()->clone() : nullptr; + if (friendAddress) { + friendAddress->clean(); + friendsManager->appendUnknownFriend(friendAddress, f); + if (friendsManager->isInOtherAddresses( + Utils::coreStringToAppString(friendAddress->asStringUriOnly()))) { + friendsManager->removeOtherAddress(Utils::coreStringToAppString(friendAddress->asStringUriOnly())); + } } } auto fList = f ? f->getFriendList() : nullptr; @@ -128,7 +132,7 @@ void MagicSearchModel::updateFriendListWithFriend(const std::shared_ptrgetAddresses()) { - auto existingFriend = friendList->findFriendByAddress(address); + auto existingFriend = friendList ? friendList->findFriendByAddress(address) : nullptr; if (existingFriend) { friendList->removeFriend(existingFriend); friendList->addFriend(linphoneFriend); @@ -136,7 +140,7 @@ void MagicSearchModel::updateFriendListWithFriend(const std::shared_ptrgetPhoneNumbers()) { - auto existingFriend = friendList->findFriendByPhoneNumber(number); + auto existingFriend = friendList ? friendList->findFriendByPhoneNumber(number) : nullptr; if (existingFriend) { friendList->removeFriend(existingFriend); friendList->addFriend(linphoneFriend); @@ -144,6 +148,6 @@ void MagicSearchModel::updateFriendListWithFriend(const std::shared_ptraddFriend(linphoneFriend); + if (friendList) friendList->addFriend(linphoneFriend); emit CoreModel::getInstance()->friendCreated(linphoneFriend); } diff --git a/Linphone/model/tool/ToolModel.cpp b/Linphone/model/tool/ToolModel.cpp index abd1ada1b..91b651596 100644 --- a/Linphone/model/tool/ToolModel.cpp +++ b/Linphone/model/tool/ToolModel.cpp @@ -20,6 +20,7 @@ #include "ToolModel.hpp" #include "core/App.hpp" +#include "core/conference/ConferenceInfoCore.hpp" #include "core/path/Paths.hpp" #include "model/core/CoreModel.hpp" #include "model/friend/FriendsManager.hpp" @@ -28,7 +29,6 @@ #include #include #include -#include "core/conference/ConferenceInfoCore.hpp" DEFINE_ABSTRACT_OBJECT(ToolModel) @@ -379,6 +379,7 @@ std::shared_ptr ToolModel::getLdapFriendList() { bool ToolModel::friendIsInFriendList(const std::shared_ptr &friendList, const std::shared_ptr &f) { + if (!friendList) return false; auto friends = friendList->getFriends(); auto it = std::find_if(friends.begin(), friends.end(), [f](std::shared_ptr linFriend) { return linFriend == f; }); diff --git a/Linphone/view/Control/Display/Chat/ChatMessagesListView.qml b/Linphone/view/Control/Display/Chat/ChatMessagesListView.qml index 6cfe7918d..5b4f2b4e2 100644 --- a/Linphone/view/Control/Display/Chat/ChatMessagesListView.qml +++ b/Linphone/view/Control/Display/Chat/ChatMessagesListView.qml @@ -60,7 +60,7 @@ ListView { header: Item { visible: mainItem.chat && mainItem.chat.core.isEncrypted - height: headerMessage.height + Math.round(50 * DefaultStyle.dp) + height: visible ? headerMessage.height + Math.round(50 * DefaultStyle.dp) : 0 width: headerMessage.width anchors.horizontalCenter: parent.horizontalCenter Control.Control {