Overlay/net-im/telegram-desktop/files/tdesktop-3.6.1-fix-double-d...

47 lines
1.8 KiB
Diff

Description: Do not capture buttons in AccountsList that belong to inner VerticalLayout widget
This fixes a use-after-free error (double destruction) in the main menu right after account switching.
Bug-Debian: https://bugs.debian.org/1008156
Bug-Ubuntu: https://launchpad.net/bugs/1967673
Forwarded: https://github.com/telegramdesktop/tdesktop/pull/24301
Author: Nicholas Guriev <guriev-ns@ya.ru>
Last-Update: Sat, 09 Apr 2022 13:47:55 +0300
diff --git a/Telegram/SourceFiles/settings/settings_information.cpp b/Telegram/SourceFiles/settings/settings_information.cpp
index 092194dcf5ce..08365a9a0c27 100644
--- a/Telegram/SourceFiles/settings/settings_information.cpp
+++ b/Telegram/SourceFiles/settings/settings_information.cpp
@@ -78,9 +78,7 @@ class AccountsList final {
int _outerIndex = 0;
Ui::SlideWrap<Ui::SettingsButton> *_addAccount = nullptr;
- base::flat_map<
- not_null<Main::Account*>,
- base::unique_qptr<Ui::SettingsButton>> _watched;
+ base::flat_map<not_null<Main::Account*>, Ui::SettingsButton*> _watched;
base::unique_qptr<Ui::PopupMenu> _contextMenu;
std::unique_ptr<Ui::VerticalLayoutReorder> _reorder;
@@ -730,7 +728,7 @@ void AccountsList::rebuild() {
order.reserve(inner->count());
for (auto i = 0; i < inner->count(); i++) {
for (const auto &[account, button] : _watched) {
- if (button.get() == inner->widgetAt(i)) {
+ if (button == inner->widgetAt(i)) {
order.push_back(account->session().uniqueId());
}
}
@@ -769,11 +767,11 @@ void AccountsList::rebuild() {
account,
std::move(activate));
};
- button.reset(inner->add(MakeAccountButton(
+ button = inner->add(MakeAccountButton(
inner,
_controller,
account,
- std::move(callback))));
+ std::move(callback)));
}
}
inner->resizeToWidth(_outer->width());