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,8 +412,12 @@ SentAsyncWebRequest::Impl::Impl(SentAsyncWebRequest* self, AsyncWebRequest const
then(*m_self, ret); then(*m_self, ret);
l.lock(); l.lock();
} }
std::lock_guard __(RUNNING_REQUESTS_MUTEX); // Delay the destruction of SentAsyncWebRequest till the next frame
RUNNING_REQUESTS.erase(m_id); // 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(); }).detach();
} }
@ -477,12 +481,8 @@ void SentAsyncWebRequest::Impl::error(std::string const& error, int code) {
l.lock(); l.lock();
} }
} }
// Delay the destruction of SentAsyncWebRequest till the next frame std::lock_guard _(RUNNING_REQUESTS_MUTEX);
// otherwise we'd have an use-after-free RUNNING_REQUESTS.erase(m_id);
Loader::get()->queueInMainThread([m_id = m_id] {
std::lock_guard _(RUNNING_REQUESTS_MUTEX);
RUNNING_REQUESTS.erase(m_id);
});
}); });
} }