From 81989406073a70f7e9b17f03dee78ed7be5e978a Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Wed, 14 Mar 2018 21:22:57 -0700 Subject: [PATCH] fix(widget): Fix double free crash on group leave Fix #5004 --- src/widget/widget.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 2c860a21b..542b64765 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -1840,7 +1840,12 @@ void Widget::onGroupPeerAudioPlaying(int groupnumber, int peernumber) void Widget::removeGroup(Group* g, bool fake) { auto groupId = g->getId(); - auto widget = groupWidgets[groupId]; + auto groupWidgetIt = groupWidgets.find(groupId); + if (groupWidgetIt == groupWidgets.end()) { + qWarning() << "Tried to remove group" << groupId << "but GroupWidget doesn't exist"; + return; + } + auto widget = groupWidgetIt.value(); widget->setAsInactiveChatroom(); if (static_cast(widget) == activeChatroomWidget) { activeChatroomWidget = nullptr; @@ -1854,15 +1859,16 @@ void Widget::removeGroup(Group* g, bool fake) } Nexus::getCore()->removeGroup(groupId, fake); - contactListWidget->removeGroupWidget(widget); + contactListWidget->removeGroupWidget(widget); // deletes widget groupWidgets.remove(groupId); - delete widget; - - auto chatForm = groupChatForms[groupId]; - groupChatForms.remove(groupId); - delete chatForm; - + auto groupChatFormIt = groupChatForms.find(groupId); + if (groupChatFormIt == groupChatForms.end()) { + qWarning() << "Tried to remove group" << groupId << "but GroupChatForm doesn't exist"; + return; + } + groupChatForms.erase(groupChatFormIt); + delete groupChatFormIt.value(); delete g; if (contentLayout && contentLayout->mainHead->layout()->isEmpty()) { onAddClicked();