From b6876733ba4d49d99269a290c170b1c3716e35d4 Mon Sep 17 00:00:00 2001 From: Alexandr Akulich Date: Tue, 29 Sep 2015 16:47:45 +0500 Subject: QXmppTransferManager: Fixed device ownership. - sendFile() without a device argument now set Job as a parent for the constructed (own) device. - sendFile() with a device argument does not reparent the device anymore. --- src/client/QXmppTransferManager.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/client/QXmppTransferManager.cpp b/src/client/QXmppTransferManager.cpp index 6fb2da75..0784279e 100644 --- a/src/client/QXmppTransferManager.cpp +++ b/src/client/QXmppTransferManager.cpp @@ -1307,7 +1307,7 @@ QXmppTransferJob *QXmppTransferManager::sendFile(const QString &jid, const QStri fileInfo.setDescription(description); // open file - QIODevice *device = new QFile(filePath); + QIODevice *device = new QFile(filePath, this); if (!device->open(QIODevice::ReadOnly)) { warning(QString("Could not read from %1").arg(filePath)); @@ -1342,6 +1342,7 @@ QXmppTransferJob *QXmppTransferManager::sendFile(const QString &jid, const QStri /// Returns 0 if the \a jid is not valid. /// /// \note The recipient's \a jid must be a full JID with a resource, for instance "user@host/resource". +/// \note The ownership of the \a device should be managed by the caller. /// QXmppTransferJob *QXmppTransferManager::sendFile(const QString &jid, QIODevice *device, const QXmppTransferFileInfo &fileInfo, const QString &sid) @@ -1361,8 +1362,6 @@ QXmppTransferJob *QXmppTransferManager::sendFile(const QString &jid, QIODevice * job->d->sid = sid; job->d->fileInfo = fileInfo; job->d->iodevice = device; - if (device) - device->setParent(job); // check file is open if (!device || !device->isReadable()) -- cgit v1.2.3 From 032c2c0a886a5b66d0460e6c4ddad1fd6c99f72b Mon Sep 17 00:00:00 2001 From: Alexandr Akulich Date: Sun, 11 Oct 2015 02:29:01 +0500 Subject: QXmppTransferManager: Close only devices which we opened. sendFile() method expects the device to be opened, but QXmppTransferJob::terminate() closes the dev unconditionaly, which breaks reusable QIODevice workflow. Introduce a private boolean variable saying "we created this device". --- src/client/QXmppTransferManager.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/client/QXmppTransferManager.cpp b/src/client/QXmppTransferManager.cpp index 0784279e..d0741511 100644 --- a/src/client/QXmppTransferManager.cpp +++ b/src/client/QXmppTransferManager.cpp @@ -204,6 +204,7 @@ public: QString requestId; QXmppTransferJob::State state; QTime transferStart; + bool deviceIsOwn; // file meta-data QXmppTransferFileInfo fileInfo; @@ -225,6 +226,7 @@ QXmppTransferJobPrivate::QXmppTransferJobPrivate() iodevice(0), method(QXmppTransferJob::NoMethod), state(QXmppTransferJob::OfferState), + deviceIsOwn(false), ibbSequence(0), socksSocket(0) { @@ -426,7 +428,7 @@ void QXmppTransferJob::terminate(QXmppTransferJob::Error cause) d->state = FinishedState; // close IO device - if (d->iodevice) + if (d->iodevice && d->deviceIsOwn) d->iodevice->close(); // close socket @@ -1332,6 +1334,7 @@ QXmppTransferJob *QXmppTransferManager::sendFile(const QString &jid, const QStri // create job QXmppTransferJob *job = sendFile(jid, device, fileInfo); job->setLocalFileUrl(QUrl::fromLocalFile(filePath)); + job->d->deviceIsOwn = true; return job; } -- cgit v1.2.3