diff --git a/src/common/checksums.cpp b/src/common/checksums.cpp index 3940779d7d..1a15b8aa43 100644 --- a/src/common/checksums.cpp +++ b/src/common/checksums.cpp @@ -208,6 +208,10 @@ ComputeChecksum::ComputeChecksum(QObject *parent) { } +ComputeChecksum::~ComputeChecksum() +{ +} + void ComputeChecksum::setChecksumType(const QByteArray &type) { _checksumType = type; @@ -221,13 +225,13 @@ QByteArray ComputeChecksum::checksumType() const void ComputeChecksum::start(const QString &filePath) { qCInfo(lcChecksums) << "Computing" << checksumType() << "checksum of" << filePath << "in a thread"; - _file = new QFile(filePath, this); + _file.reset(new QFile(filePath)); if (!_file->open(QIODevice::ReadOnly)) { qCWarning(lcChecksums) << "Could not open file" << filePath << "for reading to compute a checksum" << _file->errorString(); emit done(QByteArray(), QByteArray()); return; } - start(_file); + start(_file.get()); } void ComputeChecksum::start(QIODevice *device) @@ -286,8 +290,7 @@ QByteArray ComputeChecksum::computeNow(QIODevice *device, const QByteArray &chec void ComputeChecksum::slotCalculationDone() { // Close the file and delete the instance - if (_file) - delete _file; + _file.reset(nullptr); QByteArray checksum = _watcher.future().result(); if (!checksum.isNull()) { diff --git a/src/common/checksums.h b/src/common/checksums.h index db9642c5f0..7ceda9284d 100644 --- a/src/common/checksums.h +++ b/src/common/checksums.h @@ -25,6 +25,8 @@ #include #include +#include + class QFile; namespace OCC { @@ -82,6 +84,7 @@ class OCSYNC_EXPORT ComputeChecksum : public QObject Q_OBJECT public: explicit ComputeChecksum(QObject *parent = 0); + ~ComputeChecksum(); /** * Sets the checksum type to be used. The default is empty. @@ -129,7 +132,7 @@ private: QByteArray _checksumType; // The convenience wrapper may open a file and must close it too - QFile *_file = nullptr; + std::unique_ptr _file; // watcher for the checksum calculation thread QFutureWatcher _watcher;