Commit 42e4d9cd authored by Raphael Kubo da Costa's avatar Raphael Kubo da Costa

main: Stop leaking pointers when we do not enter the main app loop.

In the cases where we returned before calling KApplication::exec(), we
would end up leaking pointers such as |batchJob|, |window| and
|addToArchiveJob|.

Fix it by explicitly deleting |window| (since we do not have another
QWidget to make it a child of) and making |batchJob| and
|addToArchiveJob| be children of our main KApplication so that we do not
need to explicitly delete them under any circumstances.
parent ce373bf8
......@@ -46,8 +46,8 @@
#include <QTimer>
#include <QWeakPointer>
BatchExtract::BatchExtract()
: KCompositeJob(0),
BatchExtract::BatchExtract(QObject* parent)
: KCompositeJob(parent),
m_autoSubfolder(false),
m_preservePaths(true),
m_openDestinationAfterExtraction(false)
......
......@@ -59,7 +59,7 @@ public:
/**
* Creates a new BatchExtract object.
*/
BatchExtract();
explicit BatchExtract(QObject* parent = 0);
/**
* Destroys a BatchExtract object.
......
......@@ -49,7 +49,6 @@ void ExtractHereDndPlugin::slotTriggered()
batchJob->start();
kDebug() << "Started job";
}
ExtractHereDndPlugin::ExtractHereDndPlugin(QObject* parent, const QVariantList&)
......
......@@ -129,7 +129,7 @@ int main(int argc, char **argv)
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
if (args->isSet("add") || args->isSet("add-to")) {
AddToArchive *addToArchiveJob = new AddToArchive;
AddToArchive *addToArchiveJob = new AddToArchive(&application);
application.connect(addToArchiveJob, SIGNAL(result(KJob*)), SLOT(quit()), Qt::QueuedConnection);
if (args->isSet("changetofirstpath")) {
......@@ -157,7 +157,7 @@ int main(int argc, char **argv)
addToArchiveJob->start();
} else if (args->isSet("batch")) {
BatchExtract *batchJob = new BatchExtract;
BatchExtract *batchJob = new BatchExtract(&application);
application.connect(batchJob, SIGNAL(result(KJob*)), SLOT(quit()), Qt::QueuedConnection);
for (int i = 0; i < args->count(); ++i) {
......@@ -190,6 +190,7 @@ int main(int argc, char **argv)
} else {
MainWindow *window = new MainWindow;
if (!window->loadPart()) { // if loading the part fails
delete window;
return -1;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment