1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(widget): Fix double free crash on group leave

Fix #5004
This commit is contained in:
Anthony Bilinski 2018-03-14 21:22:57 -07:00
parent b071021351
commit 8198940607
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C

View File

@ -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<GenericChatroomWidget*>(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();