From c03527823153a44433c55a2c722df651bb85027d Mon Sep 17 00:00:00 2001 From: matcool <26722564+matcool@users.noreply.github.com> Date: Sat, 3 Feb 2024 19:33:27 -0300 Subject: [PATCH] okay im bad at copying code this happened whenever the request would get converted into json and fail, and then that handler would call SentAsyncWebRequest::error instead of the expect, delaying the execution of expect by one frame, by which time the request class was already deleted. Co-Authored-By: dankmeme01 <42031238+dankmeme01@users.noreply.github.com> --- loader/src/utils/web.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/loader/src/utils/web.cpp b/loader/src/utils/web.cpp index 65769c74..0411f70f 100644 --- a/loader/src/utils/web.cpp +++ b/loader/src/utils/web.cpp @@ -412,8 +412,12 @@ SentAsyncWebRequest::Impl::Impl(SentAsyncWebRequest* self, AsyncWebRequest const then(*m_self, ret); l.lock(); } - std::lock_guard __(RUNNING_REQUESTS_MUTEX); - RUNNING_REQUESTS.erase(m_id); + // Delay the destruction of SentAsyncWebRequest till the next frame + // otherwise we'd have an use-after-free + Loader::get()->queueInMainThread([m_id = m_id] { + std::lock_guard __(RUNNING_REQUESTS_MUTEX); + RUNNING_REQUESTS.erase(m_id); + }); }); }).detach(); } @@ -477,12 +481,8 @@ void SentAsyncWebRequest::Impl::error(std::string const& error, int code) { l.lock(); } } - // Delay the destruction of SentAsyncWebRequest till the next frame - // otherwise we'd have an use-after-free - Loader::get()->queueInMainThread([m_id = m_id] { - std::lock_guard _(RUNNING_REQUESTS_MUTEX); - RUNNING_REQUESTS.erase(m_id); - }); + std::lock_guard _(RUNNING_REQUESTS_MUTEX); + RUNNING_REQUESTS.erase(m_id); }); }