From cf45065e15edfbf4d39c765cd8429c19f5819a92 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 3 Apr 2026 16:26:50 +0300 Subject: [PATCH] Guarded check-status callbacks in connection box. --- Telegram/SourceFiles/boxes/connection_box.cpp | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index dd6b6686c0..d056ebeaff 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/call_delayed.h" #include "base/qthelp_regex.h" #include "base/qthelp_url.h" +#include "base/weak_ptr.h" #include "core/application.h" #include "core/core_settings.h" #include "core/local_url_handlers.h" @@ -1566,6 +1567,7 @@ void ProxiesBoxController::ShowApplyConfirmation( Checker v4; Checker v6; rpl::variable statusValue; + bool finished = false; }; const auto state = box->lifetime().make_state(); @@ -1591,9 +1593,13 @@ void ProxiesBoxController::ShowApplyConfirmation( relayout(); }; const auto runCheck = [=] { + if (!weak) { + return; + } const auto account = controller ? &controller->session().account() : &Core::App().activeAccount(); + state->finished = false; state->statusValue = TextWithEntities{ tr::lng_proxy_box_table_checking(tr::now), }; @@ -1605,7 +1611,11 @@ void ProxiesBoxController::ShowApplyConfirmation( state->v4, state->v6, [=](Connection *raw, int ping) { + if (!weak || state->finished) { + return; + } DropProxyChecker(state->v4, state->v6, raw); + state->finished = true; ResetProxyCheckers(state->v4, state->v6); state->statusValue = TextWithEntities{ tr::lng_proxy_box_table_available( @@ -1618,12 +1628,17 @@ void ProxiesBoxController::ShowApplyConfirmation( relayout(); }, [=](Connection *raw) { + if (!weak || state->finished) { + return; + } DropProxyChecker(state->v4, state->v6, raw); if (!HasProxyCheckers(state->v4, state->v6)) { + state->finished = true; setUnavailable(); } }); if (!HasProxyCheckers(state->v4, state->v6)) { + state->finished = true; setUnavailable(); } }; @@ -1690,7 +1705,13 @@ void ProxiesBoxController::refreshChecker(Item &item) { item.checker, item.checkerv6, [=](Connection *raw, int pingTime) { - const auto item = findById(id); + const auto item = ranges::find( + _list, + id, + [](const Item &item) { return item.id; }); + if (item == end(_list)) { + return; + } DropProxyChecker(item->checker, item->checkerv6, raw); ResetProxyCheckers(item->checker, item->checkerv6); if (item->state == ItemState::Checking) { @@ -1700,7 +1721,13 @@ void ProxiesBoxController::refreshChecker(Item &item) { } }, [=](Connection *raw) { - const auto item = findById(id); + const auto item = ranges::find( + _list, + id, + [](const Item &item) { return item.id; }); + if (item == end(_list)) { + return; + } DropProxyChecker(item->checker, item->checkerv6, raw); if (!HasProxyCheckers(item->checker, item->checkerv6) && item->state == ItemState::Checking) {