mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
LibCore: Have CNetworkJob protect itself during the on_finish callback
Otherwise, the callback may trigger the destruction of the CNetworkJob and make it difficult to continue execution correctly.
This commit is contained in:
parent
5d8324f133
commit
20c957ef61
1 changed files with 8 additions and 0 deletions
|
@ -14,6 +14,10 @@ CNetworkJob::~CNetworkJob()
|
||||||
|
|
||||||
void CNetworkJob::did_finish(NonnullRefPtr<CNetworkResponse>&& response)
|
void CNetworkJob::did_finish(NonnullRefPtr<CNetworkResponse>&& response)
|
||||||
{
|
{
|
||||||
|
// NOTE: We protect ourselves here, since the on_finish callback may otherwise
|
||||||
|
// trigger destruction of this job somehow.
|
||||||
|
NonnullRefPtr<CNetworkJob> protector(*this);
|
||||||
|
|
||||||
m_response = move(response);
|
m_response = move(response);
|
||||||
#ifdef CNETWORKJOB_DEBUG
|
#ifdef CNETWORKJOB_DEBUG
|
||||||
dbg() << *this << " job did_finish!";
|
dbg() << *this << " job did_finish!";
|
||||||
|
@ -25,6 +29,10 @@ void CNetworkJob::did_finish(NonnullRefPtr<CNetworkResponse>&& response)
|
||||||
|
|
||||||
void CNetworkJob::did_fail(Error error)
|
void CNetworkJob::did_fail(Error error)
|
||||||
{
|
{
|
||||||
|
// NOTE: We protect ourselves here, since the on_finish callback may otherwise
|
||||||
|
// trigger destruction of this job somehow.
|
||||||
|
NonnullRefPtr<CNetworkJob> protector(*this);
|
||||||
|
|
||||||
m_error = error;
|
m_error = error;
|
||||||
#ifdef CNETWORKJOB_DEBUG
|
#ifdef CNETWORKJOB_DEBUG
|
||||||
dbgprintf("%s{%p} job did_fail! error: %u (%s)\n", class_name(), this, (unsigned)error, to_string(error));
|
dbgprintf("%s{%p} job did_fail! error: %u (%s)\n", class_name(), this, (unsigned)error, to_string(error));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue