summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-09-19 18:18:19 +0430
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-09-19 21:10:23 +0430
commit81a0301d4dd761bc4fd0dd077877ab95c6957364 (patch)
tree966082bdb5290457db52c32ed4116c11a79c7579 /Userland/Libraries/LibCore
parent436693c0c907b9a15bd6cccc07304e6332bc7b7b (diff)
downloadserenity-81a0301d4dd761bc4fd0dd077877ab95c6957364.zip
LibCore+RequestServer: Ignore callbacks for cancelled network jobs
Also cancel the jobs when they're destroyed. This makes sure that jobs whose owners have discarded don't end up crashing because of a did_fail().
Diffstat (limited to 'Userland/Libraries/LibCore')
-rw-r--r--Userland/Libraries/LibCore/NetworkJob.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/NetworkJob.cpp b/Userland/Libraries/LibCore/NetworkJob.cpp
index dd8b15ed00..c79f3085b4 100644
--- a/Userland/Libraries/LibCore/NetworkJob.cpp
+++ b/Userland/Libraries/LibCore/NetworkJob.cpp
@@ -29,6 +29,9 @@ void NetworkJob::shutdown()
void NetworkJob::did_finish(NonnullRefPtr<NetworkResponse>&& response)
{
+ if (is_cancelled())
+ return;
+
// NOTE: We protect ourselves here, since the on_finish callback may otherwise
// trigger destruction of this job somehow.
NonnullRefPtr<NetworkJob> protector(*this);
@@ -42,6 +45,9 @@ void NetworkJob::did_finish(NonnullRefPtr<NetworkResponse>&& response)
void NetworkJob::did_fail(Error error)
{
+ if (is_cancelled())
+ return;
+
// NOTE: We protect ourselves here, since the on_finish callback may otherwise
// trigger destruction of this job somehow.
NonnullRefPtr<NetworkJob> protector(*this);
@@ -55,6 +61,9 @@ void NetworkJob::did_fail(Error error)
void NetworkJob::did_progress(Optional<u32> total_size, u32 downloaded)
{
+ if (is_cancelled())
+ return;
+
// NOTE: We protect ourselves here, since the callback may otherwise
// trigger destruction of this job somehow.
NonnullRefPtr<NetworkJob> protector(*this);