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

--- tdesktop-3.6.1-full.orig/Telegram/SourceFiles/settings/settings_information.cpp
+++ tdesktop-3.6.1-full/Telegram/SourceFiles/settings/settings_information.cpp
@@ -78,9 +78,7 @@
 	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 @@
 				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 @@
 					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());
