summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Sterna <tomek@xiaoka.com>2015-01-11 00:41:59 +0100
committerTomasz Sterna <tomek@xiaoka.com>2015-01-11 00:41:59 +0100
commit1ec7ec1bda20f0c037b4d2fa834f4acf0d35e9d3 (patch)
tree3e81b8b84481a3c1ea0a07efa0b16fa11e97e436
parentf92941ec79d8ddaf772a7f1e21600c447af87ecd (diff)
Manual heap object deletion is leaky - let's not do it
-rw-r--r--daemon/appinfo.cpp4
-rw-r--r--daemon/bankmanager.cpp34
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<QIODevice> 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<QIODevice> 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<QIODevice> 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<QIODevice> 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();
});