From 2a0c71d0d405e02aa4159df7d9e59a24ed3d5c4c Mon Sep 17 00:00:00 2001 From: Diadlo Date: Sun, 11 Mar 2018 22:50:22 +0300 Subject: [PATCH] fix: Fix crash on manipulation with friend Fix #4991 --- src/widget/widget.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 187211b96..2c860a21b 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -1489,7 +1489,7 @@ void Widget::removeFriend(Friend* f, bool fake) } const uint32_t friendId = f->getId(); - FriendWidget* widget = friendWidgets[friendId]; + auto widget = friendWidgets[friendId]; widget->setAsInactiveChatroom(); if (widget == activeChatroomWidget) { activeChatroomWidget = nullptr; @@ -1509,6 +1509,11 @@ void Widget::removeFriend(Friend* f, bool fake) friendWidgets.remove(friendId); delete widget; + + auto chatForm = chatForms[friendId]; + chatForms.remove(friendId); + delete chatForm; + delete f; if (contentLayout && contentLayout->mainHead->layout()->isEmpty()) { onAddClicked(); @@ -1834,25 +1839,30 @@ void Widget::onGroupPeerAudioPlaying(int groupnumber, int peernumber) void Widget::removeGroup(Group* g, bool fake) { - GroupWidget* widget = groupWidgets[g->getId()]; + auto groupId = g->getId(); + auto widget = groupWidgets[groupId]; widget->setAsInactiveChatroom(); if (static_cast(widget) == activeChatroomWidget) { activeChatroomWidget = nullptr; onAddClicked(); } - int groupId = g->getId(); GroupList::removeGroup(groupId, fake); ContentDialog* contentDialog = ContentDialog::getGroupDialog(groupId); if (contentDialog != nullptr) { contentDialog->removeGroup(groupId); } - groupWidgets.remove(groupId); - Nexus::getCore()->removeGroup(groupId, fake); contactListWidget->removeGroupWidget(widget); + groupWidgets.remove(groupId); + delete widget; + + auto chatForm = groupChatForms[groupId]; + groupChatForms.remove(groupId); + delete chatForm; + delete g; if (contentLayout && contentLayout->mainHead->layout()->isEmpty()) { onAddClicked();