1
0
mirror of https://github.com/chylex/Nextcloud-Desktop.git synced 2025-05-07 17:34:09 +02:00

Fix memory leak with device pointer

Downstream of https://github.com/owncloud/client/pull/6856

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2019-05-08 19:41:48 +02:00
parent 92a5e64487
commit c2e3cbca31
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
3 changed files with 12 additions and 11 deletions

View File

@ -92,19 +92,19 @@ private:
public:
// Takes ownership of the device
explicit PUTFileJob(AccountPtr account, const QString &path, QIODevice *device,
explicit PUTFileJob(AccountPtr account, const QString &path, std::unique_ptr<QIODevice> device,
const QMap<QByteArray, QByteArray> &headers, int chunk, QObject *parent = nullptr)
: AbstractNetworkJob(account, path, parent)
, _device(device)
, _device(device.release())
, _headers(headers)
, _chunk(chunk)
{
_device->setParent(this);
}
explicit PUTFileJob(AccountPtr account, const QUrl &url, QIODevice *device,
explicit PUTFileJob(AccountPtr account, const QUrl &url, std::unique_ptr<QIODevice> device,
const QMap<QByteArray, QByteArray> &headers, int chunk, QObject *parent = nullptr)
: AbstractNetworkJob(account, QString(), parent)
, _device(device)
, _device(device.release())
, _headers(headers)
, _url(url)
, _chunk(chunk)

View File

@ -305,7 +305,7 @@ void PropagateUploadFileNG::startNextChunk()
return;
}
auto device = new UploadDevice(&propagator()->_bandwidthManager);
auto device = std::make_unique<UploadDevice>(&propagator()->_bandwidthManager);
const QString fileName = _fileToUpload._path;
if (!device->prepareAndOpen(fileName, _sent, _currentChunkSize)) {
@ -328,13 +328,14 @@ void PropagateUploadFileNG::startNextChunk()
QUrl url = chunkUrl(_currentChunk);
// job takes ownership of device via a QScopedPointer. Job deletes itself when finishing
PUTFileJob *job = new PUTFileJob(propagator()->account(), url, device, headers, _currentChunk, this);
auto devicePtr = device.get(); // for connections later
PUTFileJob *job = new PUTFileJob(propagator()->account(), url, std::move(device), headers, _currentChunk, this);
_jobs.append(job);
connect(job, &PUTFileJob::finishedSignal, this, &PropagateUploadFileNG::slotPutFinished);
connect(job, &PUTFileJob::uploadProgress,
this, &PropagateUploadFileNG::slotUploadProgress);
connect(job, &PUTFileJob::uploadProgress,
device, &UploadDevice::slotJobUploadProgress);
devicePtr, &UploadDevice::slotJobUploadProgress);
connect(job, &QObject::destroyed, this, &PropagateUploadFileCommon::slotJobDestroyed);
job->start();
propagator()->_activeJobList.append(this);

View File

@ -89,7 +89,7 @@ void PropagateUploadFileV1::startNextChunk()
QString path = _fileToUpload._file;
UploadDevice *device = new UploadDevice(&propagator()->_bandwidthManager);
auto device = std::make_unique<UploadDevice>(&propagator()->_bandwidthManager);
qint64 chunkStart = 0;
qint64 currentChunkSize = fileSize;
bool isFinalChunk = false;
@ -134,16 +134,16 @@ void PropagateUploadFileV1::startNextChunk()
}
// Soft error because this is likely caused by the user modifying his files while syncing
abortWithError(SyncFileItem::SoftError, device->errorString());
delete device;
return;
}
// job takes ownership of device via a QScopedPointer. Job deletes itself when finishing
PUTFileJob *job = new PUTFileJob(propagator()->account(), propagator()->_remoteFolder + path, device, headers, _currentChunk, this);
auto devicePtr = device.get(); // for connections later
PUTFileJob *job = new PUTFileJob(propagator()->account(), propagator()->_remoteFolder + path, std::move(device), headers, _currentChunk, this);
_jobs.append(job);
connect(job, &PUTFileJob::finishedSignal, this, &PropagateUploadFileV1::slotPutFinished);
connect(job, &PUTFileJob::uploadProgress, this, &PropagateUploadFileV1::slotUploadProgress);
connect(job, &PUTFileJob::uploadProgress, device, &UploadDevice::slotJobUploadProgress);
connect(job, &PUTFileJob::uploadProgress, devicePtr, &UploadDevice::slotJobUploadProgress);
connect(job, &QObject::destroyed, this, &PropagateUploadFileCommon::slotJobDestroyed);
if (isFinalChunk)
adjustLastJobTimeout(job, fileSize);