summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-11-23 21:42:02 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-11-23 21:42:02 +0100
commit20c957ef6102fb7de070ae234812ba7c8fcef570 (patch)
tree2c50d6a1447d970705e29b3d558db64baf669e24 /Libraries
parent5d8324f133b4c2cc3be40ce3fe51771934bbd070 (diff)
downloadserenity-20c957ef6102fb7de070ae234812ba7c8fcef570.zip
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.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibCore/CNetworkJob.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/Libraries/LibCore/CNetworkJob.cpp b/Libraries/LibCore/CNetworkJob.cpp
index f668fac9a3..7cc563f26b 100644
--- a/Libraries/LibCore/CNetworkJob.cpp
+++ b/Libraries/LibCore/CNetworkJob.cpp
@@ -14,6 +14,10 @@ CNetworkJob::~CNetworkJob()
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);
#ifdef CNETWORKJOB_DEBUG
dbg() << *this << " job did_finish!";
@@ -25,6 +29,10 @@ void CNetworkJob::did_finish(NonnullRefPtr<CNetworkResponse>&& response)
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;
#ifdef CNETWORKJOB_DEBUG
dbgprintf("%s{%p} job did_fail! error: %u (%s)\n", class_name(), this, (unsigned)error, to_string(error));