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:
parent
92a5e64487
commit
c2e3cbca31
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user