Skip to content

Commit

Permalink
race condition fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chapati committed Aug 10, 2021
1 parent 3cf5676 commit 20b4eb8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/src/filesystemhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Socket> qsp = socket;
connect(copier, &QIODeviceCopier::finished, [qsp]() {
if (qsp)
{
qsp->close();
}
});

// Stop the copier if the socket is disconnected
Expand Down

0 comments on commit 20b4eb8

Please sign in to comment.