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 @@ -91,10 +91,12 @@ class HTTPRequest
bool m_bNeedsProgressUpdate = false;
bool m_bIsStarted = false;
bool m_bIsComplete = false;
bool m_bSkipCallback = false;


struct curl_slist* headers = nullptr;

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 callbacks during shutdown to avoid use-after-free
pRequest->Threaded_SetComplete(m->data.result, true);
delete pRequest;
m_vecRequestsInFlight.erase(it);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void HTTPRequest::OnResponsePartialWrite(std::uint8_t* pBuffer, size_t numBytes)

void HTTPRequest::InvokeCallbackIfComplete()
{
if (m_bIsComplete)
if (m_bIsComplete && !m_bSkipCallback)
{
if (m_completionCallback != nullptr)
{
Expand Down Expand Up @@ -133,12 +133,13 @@ bool HTTPRequest::InvokeDelayAction()

#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;

// finalize the size, so we can use .size etc
m_vecBuffer.resize(m_currentBufSize_Used);
Expand Down
Loading