From b49fb258cebaefd3e720459f07c8d0bfaa4856c0 Mon Sep 17 00:00:00 2001 From: pajlada Date: Tue, 30 Dec 2025 17:10:42 +0100 Subject: [PATCH] fix: more carefully use app in NetworkPrivate/NetworkTask (#6698) --- CHANGELOG.md | 1 + src/common/network/NetworkPrivate.cpp | 20 ++++++++++++++++++-- src/common/network/NetworkTask.cpp | 19 ++++++++++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d82c05c..e0aca98d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ - Bugfix: Forward query params to websocket URLs. (#6141) - Bugfix: Fixed Lua errors from handlers of HTTP requests not being logged. (#6452) - Bugfix: Fixed restore button not showing on Windows. (#6565) +- Bugfix: Fixed a crash that could occur when network requests were loading/saving cache as Chatterino was being shut down. (#6698) - Bugfix: Fixed popups and the overlay not being draggable on Wayland. (#6573) - Bugfix: Fixed middle-clicking usernames in a local channel opening an invalid viewercard. (#6577) - Bugfix: Added `desktop-entry` hint to Linux notifications. (#6615) diff --git a/src/common/network/NetworkPrivate.cpp b/src/common/network/NetworkPrivate.cpp index c7f0625e..4b70692c 100644 --- a/src/common/network/NetworkPrivate.cpp +++ b/src/common/network/NetworkPrivate.cpp @@ -59,8 +59,24 @@ void loadUncached(std::shared_ptr &&data) void loadCached(std::shared_ptr &&data) { - QFile cachedFile(getApp()->getPaths().cacheDirectory() + "/" + - data->getHash()); + if (isAppAboutToQuit()) + { + qCDebug(chatterinoHTTP) + << "Skipping cached network load " << data->request.url() + << "because app is about to quit"; + return; + } + + auto *app = tryGetApp(); + if (!app) + { + qCDebug(chatterinoHTTP) + << "Skipping cached network load " << data->request.url() + << "because app is about to quit"; + return; + } + + QFile cachedFile(app->getPaths().cacheDirectory() + "/" + data->getHash()); if (!cachedFile.exists() || !cachedFile.open(QIODevice::ReadOnly)) { diff --git a/src/common/network/NetworkTask.cpp b/src/common/network/NetworkTask.cpp index c2640a0b..7535de6f 100644 --- a/src/common/network/NetworkTask.cpp +++ b/src/common/network/NetworkTask.cpp @@ -141,7 +141,24 @@ void NetworkTask::logReply() void NetworkTask::writeToCache(const QByteArray &bytes) const { std::ignore = QtConcurrent::run([data = this->data_, bytes] { - QFile cachedFile(getApp()->getPaths().cacheDirectory() + "/" + + if (isAppAboutToQuit()) + { + qCDebug(chatterinoHTTP) + << "Skipping cache write for" << data->request.url() + << "because app is about to quit"; + return; + } + + auto *app = tryGetApp(); + if (!app) + { + qCDebug(chatterinoHTTP) + << "Skipping cache write for" << data->request.url() + << "because app is null"; + return; + } + + QFile cachedFile(app->getPaths().cacheDirectory() + "/" + data->getHash()); if (cachedFile.open(QIODevice::WriteOnly))