Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class HTTPRequest
bool InvokeDelayAction();
bool WaitingDelayAction() const { return m_timeRequestComplete != -1; }
#endif
void Threaded_SetComplete(CURLcode result);
void Threaded_SetComplete(CURLcode result, bool bSkipCallback = false);

// mainly used for downloads
std::vector<uint8_t> GetBuffer() { return m_vecBuffer; }
Expand Down Expand Up @@ -97,4 +97,4 @@ class HTTPRequest
std::function<void(bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq)> m_completionCallback = nullptr;

std::function<void(size_t bytesReceived)> m_progressCallback = nullptr;
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ void HTTPManager::Shutdown()
HTTPRequest* pRequest = *it;
if (pRequest != nullptr && pRequest->EasyHandleMatches(pCurlHandle))
{
pRequest->Threaded_SetComplete(m->data.result);
// Skip callback invocation during shutdown to avoid use-after-free
pRequest->Threaded_SetComplete(m->data.result, true);
delete pRequest;
m_vecRequestsInFlight.erase(it);
break;
Expand Down Expand Up @@ -226,7 +227,8 @@ void HTTPManager::Tick()
#if defined(ARTIFICIAL_DELAY_HTTP_REQUESTS)
pRequest->SetWaitingDelay(m->data.result);
#else
pRequest->Threaded_SetComplete(m->data.result);
// Normal operation - invoke callbacks
pRequest->Threaded_SetComplete(m->data.result, false);
vecItemsToRemove.push_back(pRequest);
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@

HTTPRequest::~HTTPRequest()
{
HTTPManager* pHTTPManager = NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager();
pHTTPManager->RemoveHandleFromMulti(m_pCURL);
// Safely check if the manager is still valid before attempting to use it
NGMP_OnlineServicesManager* pOnlineServicesMgr = NGMP_OnlineServicesManager::GetInstance();
if (pOnlineServicesMgr != nullptr)
{
HTTPManager* pHTTPManager = pOnlineServicesMgr->GetHTTPManager();
if (pHTTPManager != nullptr)
{
pHTTPManager->RemoveHandleFromMulti(m_pCURL);
}
}

curl_easy_cleanup(m_pCURL);

Expand Down Expand Up @@ -90,7 +98,7 @@

void HTTPRequest::InvokeCallbackIfComplete()
{
if (m_bIsComplete)
if (m_bIsComplete && !m_bSkipCallback)

Check failure on line 101 in GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/HTTP/HTTPRequest.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32-profile+e

'm_bSkipCallback': undeclared identifier

Check failure on line 101 in GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/HTTP/HTTPRequest.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32+e

'm_bSkipCallback': undeclared identifier
{
if (m_completionCallback != nullptr)
{
Expand Down Expand Up @@ -123,7 +131,8 @@
int64_t currTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::utc_clock::now().time_since_epoch()).count();
if (currTime - m_timeRequestComplete > 2000)
{
Threaded_SetComplete(m_pendingCURLCode);
// Normal operation with artificial delay - invoke callbacks
Threaded_SetComplete(m_pendingCURLCode, false);
return true;
}
}
Expand All @@ -133,12 +142,13 @@

#endif

void HTTPRequest::Threaded_SetComplete(CURLcode result)
void HTTPRequest::Threaded_SetComplete(CURLcode result, bool bSkipCallback)
{
// store response code
curl_easy_getinfo(m_pCURL, CURLINFO_RESPONSE_CODE, &m_responseCode);

m_bIsComplete = true;
m_bSkipCallback = bSkipCallback;

Check failure on line 151 in GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/HTTP/HTTPRequest.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32-profile+e

'm_bSkipCallback': undeclared identifier

Check failure on line 151 in GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/HTTP/HTTPRequest.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32+e

'm_bSkipCallback': undeclared identifier

// finalize the size, so we can use .size etc
m_vecBuffer.resize(m_currentBufSize_Used);
Expand Down Expand Up @@ -171,8 +181,11 @@

NetworkLog(ELogVerbosity::LOG_RELEASE, "[%p|%s] Response was %d - %s!", this, strURIRedacted.c_str(), m_responseCode, strResponse.c_str());

// trigger callback
InvokeCallbackIfComplete();
// trigger callback only if not skipping
if (!bSkipCallback)
{
InvokeCallbackIfComplete();
}
}

void HTTPRequest::PlatformStartRequest()
Expand Down
Loading