From 1ec7ec1bda20f0c037b4d2fa834f4acf0d35e9d3 Mon Sep 17 00:00:00 2001 From: Tomasz Sterna Date: Sun, 11 Jan 2015 00:41:59 +0100 Subject: Manual heap object deletion is leaky - let's not do it --- daemon/appinfo.cpp | 4 ++-- daemon/bankmanager.cpp | 34 ++++++++++++---------------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/daemon/appinfo.cpp b/daemon/appinfo.cpp index 939b569..f4a32c3 100644 --- a/daemon/appinfo.cpp +++ b/daemon/appinfo.cpp @@ -179,7 +179,7 @@ QString AppInfo::getJSApp() const { if (!isValid() || !isLocal()) return QString(); - QIODevice *appJS = openFile(AppInfo::APPJS); + QScopedPointer appJS(openFile(AppInfo::APPJS)); if (!appJS) { qCWarning(l) << "cannot find app" << d->path << "app.js"; return QString(); @@ -205,7 +205,7 @@ AppInfo AppInfo::fromPath(const QString &path) info.d->path = path; - QIODevice *appInfoJSON = info.openFile(AppInfo::INFO); + QScopedPointer appInfoJSON(info.openFile(AppInfo::INFO)); if (!appInfoJSON) { qCWarning(l) << "cannot find app" << path << "info json"; return AppInfo(); diff --git a/daemon/bankmanager.cpp b/daemon/bankmanager.cpp index f4bb7b3..69e6821 100644 --- a/daemon/bankmanager.cpp +++ b/daemon/bankmanager.cpp @@ -80,41 +80,36 @@ bool BankManager::uploadApp(const QUuid &uuid, int slot) qCDebug(l) << "about to install app" << info.shortName() << "into slot" << slot; - QIODevice *binaryFile = info.openFile(AppInfo::BINARY); + QSharedPointer binaryFile(info.openFile(AppInfo::BINARY)); if (!binaryFile->open(QIODevice::ReadOnly)) { qCWarning(l) << "failed to open" << info.shortName() << "AppInfo::BINARY" << binaryFile->errorString(); - delete binaryFile; return false; } qCDebug(l) << "binary file size is" << binaryFile->size(); - QIODevice *resourceFile = info.openFile(AppInfo::RESOURCES); - if (resourceFile && !resourceFile->open(QIODevice::ReadOnly)) { - qCWarning(l) << "failed to open " << info.shortName() - << "AppInfo::RESOURCES" << resourceFile->errorString(); - delete binaryFile; - delete resourceFile; - return false; - } - // Mark the slot as used, but without any app, just in case. _slots[slot].used = true; _slots[slot].name.clear(); _slots[slot].uuid = QUuid(); - upload->uploadAppBinary(slot, binaryFile, - [this, binaryFile, resourceFile, slot]() { + upload->uploadAppBinary(slot, binaryFile.data(), + [this, info, binaryFile, slot]() { qCDebug(l) << "app binary upload succesful"; - delete binaryFile; // Proceed to upload the resource file + QSharedPointer resourceFile(info.openFile(AppInfo::RESOURCES)); if (resourceFile) { - upload->uploadAppResources(slot, resourceFile, + if (!resourceFile->open(QIODevice::ReadOnly)) { + qCWarning(l) << "failed to open" << info.shortName() + << "AppInfo::RESOURCES" << resourceFile->errorString(); + _refresh->start(); + return; + } + upload->uploadAppResources(slot, resourceFile.data(), [this, resourceFile, slot]() { qCDebug(l) << "app resources upload succesful"; - delete resourceFile; // Upload succesful // Tell the watch to reload the slot @@ -127,8 +122,6 @@ bool BankManager::uploadApp(const QUuid &uuid, int slot) }); }, [this, resourceFile](int code) { qCWarning(l) << "app resources upload failed" << code; - delete resourceFile; - _refresh->start(); }); @@ -143,11 +136,8 @@ bool BankManager::uploadApp(const QUuid &uuid, int slot) _refresh->start(); }); } - }, [this, binaryFile, resourceFile](int code) { + }, [this](int code) { qCWarning(l) << "app binary upload failed" << code; - delete binaryFile; - delete resourceFile; - _refresh->start(); }); -- cgit v1.2.3