Skip to content

Commit 420a6ec

Browse files
committed
Addendum #2 to 5429339 (Server list crash fixes)
1 parent 78ae239 commit 420a6ec

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

Client/core/ServerBrowser/CServerBrowser.RemoteMasterServer.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ CRemoteMasterServer::~CRemoteMasterServer()
9292
void CRemoteMasterServer::Init(const SString& strURL)
9393
{
9494
m_strURL = strURL;
95-
GetHTTP()->SetMaxConnections(5);
95+
CNetHTTPDownloadManagerInterface* pHTTP = GetHTTP();
96+
if (pHTTP)
97+
pHTTP->SetMaxConnections(5);
9698
}
9799

98100
///////////////////////////////////////////////////////////////
@@ -120,12 +122,19 @@ void CRemoteMasterServer::Refresh()
120122
if (GetTickCount64_() - m_llLastRefreshTime < 60000 && m_strStage == "hasdata")
121123
return;
122124

125+
CNetHTTPDownloadManagerInterface* pHTTP = GetHTTP();
126+
if (!pHTTP)
127+
{
128+
m_strStage = "nogood";
129+
return;
130+
}
131+
123132
// Send new request
124133
m_strStage = "waitingreply";
125134
m_llLastRefreshTime = GetTickCount64_();
126135
SHttpRequestOptions options;
127136
options.uiConnectionAttempts = 1;
128-
if (GetHTTP()->QueueFile(m_strURL, NULL, this, &CRemoteMasterServer::StaticDownloadFinished, options))
137+
if (pHTTP->QueueFile(m_strURL, NULL, this, &CRemoteMasterServer::StaticDownloadFinished, options))
129138
{
130139
m_bPendingDownload = true;
131140
AddRef(); // Keep alive
@@ -141,7 +150,17 @@ void CRemoteMasterServer::Cancel()
141150
if (!m_bPendingDownload)
142151
return;
143152

144-
if (GetHTTP()->CancelDownload(this, &CRemoteMasterServer::StaticDownloadFinished))
153+
CNetHTTPDownloadManagerInterface* pHTTP = GetHTTP();
154+
if (!pHTTP)
155+
{
156+
// HTTP manager destroyed - callback won't be called, so Release() here
157+
m_bPendingDownload = false;
158+
m_strStage.clear();
159+
Release();
160+
return;
161+
}
162+
163+
if (pHTTP->CancelDownload(this, &CRemoteMasterServer::StaticDownloadFinished))
145164
{
146165
m_bPendingDownload = false;
147166
m_strStage.clear();
@@ -200,7 +219,9 @@ void CRemoteMasterServer::DownloadFinished(const SHttpDownloadResult& result)
200219
///////////////////////////////////////////////////////////////
201220
bool CRemoteMasterServer::HasData()
202221
{
203-
GetHTTP()->ProcessQueuedFiles();
222+
CNetHTTPDownloadManagerInterface* pHTTP = GetHTTP();
223+
if (pHTTP)
224+
pHTTP->ProcessQueuedFiles();
204225
return m_strStage == "hasdata";
205226
}
206227

Client/core/ServerBrowser/CServerBrowser.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,11 @@ CServerBrowser::CServerBrowser()
372372

373373
CServerBrowser::~CServerBrowser()
374374
{
375+
// Suspend all server list activity and cancel pending network operations FIRST
376+
// This must be done before DeleteTab() destroys the server lists, and while
377+
// the network subsystem is still available (it may be destroyed before this destructor)
378+
SuspendServerLists();
379+
375380
// Save options now and disable selection handler
376381
SaveOptions(true);
377382
if (m_pPanel)
@@ -990,6 +995,13 @@ void CServerBrowser::StartRefresh(ServerBrowserType type)
990995

991996
m_iSelectedServer[index] = -1;
992997
m_bPendingRefresh[index] = false;
998+
999+
// Cancel any in-progress batch refresh to prevent iterator invalidation
1000+
// when pList->Refresh() calls Clear() on the server list
1001+
m_ListRefreshState[index].bActive = false;
1002+
m_ListRefreshState[index].pList = nullptr;
1003+
m_ListRefreshState[index].filterSnapshot.reset();
1004+
9931005
pList->Refresh();
9941006
m_bInitialRefreshDone[index] = true;
9951007
}

0 commit comments

Comments
 (0)