Skip to content

Commit 728e32c

Browse files
authored
Merge pull request #505 from GeneralsOnlineDevelopmentTeam/seer/fix/http-shutdown-uaf
bugfix(network): Prevent use-after-free during HTTP request cleanup on shutdown
2 parents 2f98875 + 4ac25f8 commit 728e32c

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

  • GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/HTTP

GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/HTTP/HTTPManager.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ void HTTPManager::Shutdown()
103103
HTTPRequest* pRequest = *it;
104104
if (pRequest != nullptr && pRequest->EasyHandleMatches(pCurlHandle))
105105
{
106-
pRequest->Threaded_SetComplete(m->data.result);
106+
// During shutdown, skip invoking the completion callback. The callback
107+
// may reference objects (e.g. NGMP_OnlineServices_StatsInterface via
108+
// captured 'this') that have already been or are being destroyed,
109+
// leading to use-after-free memory corruption and crashes in unrelated
110+
// destructors such as GameSpyMiscPreferences::~GameSpyMiscPreferences().
111+
// HTTPRequest::~HTTPRequest() handles all necessary curl handle cleanup.
107112
delete pRequest;
108113
m_vecRequestsInFlight.erase(it);
109114
break;
@@ -122,6 +127,17 @@ void HTTPManager::Shutdown()
122127

123128
NetworkLog(ELogVerbosity::LOG_RELEASE, "[HTTPManager] All in-flight requests completed");
124129

130+
// Delete any remaining in-flight requests without invoking their callbacks.
131+
// These are requests that completed via curl but were not matched above, or
132+
// requests that are still pending completion. Invoking callbacks here is unsafe
133+
// as the objects they reference may already be destroyed.
134+
for (HTTPRequest* pRequest : m_vecRequestsInFlight)
135+
{
136+
if (pRequest != nullptr)
137+
{
138+
delete pRequest;
139+
}
140+
}
125141
m_vecRequestsInFlight.clear();
126142

127143
// Now safe to cleanup

0 commit comments

Comments
 (0)