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>
This commit is contained in:
matcool 2024-02-03 19:33:27 -03:00
parent 49738e6029
commit c035278231

View file

@ -412,9 +412,13 @@ SentAsyncWebRequest::Impl::Impl(SentAsyncWebRequest* self, AsyncWebRequest const
then(*m_self, ret); then(*m_self, ret);
l.lock(); 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); std::lock_guard __(RUNNING_REQUESTS_MUTEX);
RUNNING_REQUESTS.erase(m_id); RUNNING_REQUESTS.erase(m_id);
}); });
});
}).detach(); }).detach();
} }
@ -477,13 +481,9 @@ void SentAsyncWebRequest::Impl::error(std::string const& error, int code) {
l.lock(); 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); std::lock_guard _(RUNNING_REQUESTS_MUTEX);
RUNNING_REQUESTS.erase(m_id); RUNNING_REQUESTS.erase(m_id);
}); });
});
} }
SentAsyncWebRequest::SentAsyncWebRequest() : m_impl() {} SentAsyncWebRequest::SentAsyncWebRequest() : m_impl() {}