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 @@ -44,9 +44,9 @@ class HTTPRequest
}
}

void InvokeCallbackIfComplete();
void InvokeCallbackIfComplete(bool bInvokeCallback = true);

void Threaded_SetComplete(CURLcode result);
void Threaded_SetComplete(CURLcode result, bool bInvokeCallback = true);

// mainly used for downloads
std::vector<uint8_t> GetBuffer() { return m_vecBuffer; }
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 callbacks during shutdown to avoid use-after-free
pRequest->Threaded_SetComplete(m->data.result, false);
delete pRequest;
m_vecRequestsInFlight.erase(it);
break;
Expand Down Expand Up @@ -205,7 +206,8 @@ void HTTPManager::Tick()
{
if (pRequest != nullptr && pRequest->EasyHandleMatches(pCurlHandle))
{
pRequest->Threaded_SetComplete(m->data.result);
// Invoke callbacks during normal operation
pRequest->Threaded_SetComplete(m->data.result, true);
vecItemsToRemove.push_back(pRequest);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ void HTTPRequest::OnResponsePartialWrite(std::uint8_t* pBuffer, size_t numBytes)
InvokeProgressUpdateCallback();
}

void HTTPRequest::InvokeCallbackIfComplete()
void HTTPRequest::InvokeCallbackIfComplete(bool bInvokeCallback)
{
if (m_bIsComplete)
if (m_bIsComplete && bInvokeCallback)
{
if (m_completionCallback != nullptr)
{
Expand All @@ -109,7 +109,7 @@ void HTTPRequest::InvokeCallbackIfComplete()
}
}

void HTTPRequest::Threaded_SetComplete(CURLcode result)
void HTTPRequest::Threaded_SetComplete(CURLcode result, bool bInvokeCallback)
{
// store response code
curl_easy_getinfo(m_pCURL, CURLINFO_RESPONSE_CODE, &m_responseCode);
Expand Down Expand Up @@ -148,7 +148,7 @@ void HTTPRequest::Threaded_SetComplete(CURLcode result)
NetworkLog(ELogVerbosity::LOG_RELEASE, "[%p|%s] Response was %d - %s!", this, strURIRedacted.c_str(), m_responseCode, strResponse.c_str());

// trigger callback
InvokeCallbackIfComplete();
InvokeCallbackIfComplete(bInvokeCallback);
}

void HTTPRequest::PlatformStartRequest()
Expand Down
Loading