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 9, 2021
1 parent a36b8ae commit 3cf5676
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 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);
QFile *file = new QFile(absolutePath, this);
if (!file->open(QIODevice::ReadOnly)) {
delete file;

Expand All @@ -86,15 +86,11 @@ 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);
QIODeviceCopier *copier = new QIODeviceCopier(file, socket, this);
connect(copier, &QIODeviceCopier::finished, copier, &QIODeviceCopier::deleteLater);
connect(copier, &QIODeviceCopier::finished, file, &QFile::deleteLater);

QPointer<Socket> qps = socket;
connect(copier, &QIODeviceCopier::finished, [qps]() {
if(qps) {
qps->close();
}
connect(copier, &QIODeviceCopier::finished, [socket]() {
socket->close();
});

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

0 comments on commit 3cf5676

Please sign in to comment.