From 20b4eb82ba4f733366983b8dd91577d863e12899 Mon Sep 17 00:00:00 2001 From: chapati Date: Tue, 10 Aug 2021 16:02:40 +0300 Subject: [PATCH] race condition fix --- src/src/filesystemhandler.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/src/filesystemhandler.cpp b/src/src/filesystemhandler.cpp index a74195d..61c1372 100644 --- a/src/src/filesystemhandler.cpp +++ b/src/src/filesystemhandler.cpp @@ -77,7 +77,7 @@ QByteArray FilesystemHandlerPrivate::mimeType(const QString &absolutePath) void FilesystemHandlerPrivate::processFile(Socket *socket, const QString &absolutePath) { // Attempt to open the file for reading - QFile *file = new QFile(absolutePath, this); + QFile *file = new QFile(absolutePath); if (!file->open(QIODevice::ReadOnly)) { delete file; @@ -86,11 +86,16 @@ void FilesystemHandlerPrivate::processFile(Socket *socket, const QString &absolu } // Create a QIODeviceCopier to copy the file contents to the socket - QIODeviceCopier *copier = new QIODeviceCopier(file, socket, this); + QIODeviceCopier *copier = new QIODeviceCopier(file, socket); connect(copier, &QIODeviceCopier::finished, copier, &QIODeviceCopier::deleteLater); connect(copier, &QIODeviceCopier::finished, file, &QFile::deleteLater); - connect(copier, &QIODeviceCopier::finished, [socket]() { - socket->close(); + + QPointer qsp = socket; + connect(copier, &QIODeviceCopier::finished, [qsp]() { + if (qsp) + { + qsp->close(); + } }); // Stop the copier if the socket is disconnected