From 72b26fe7f6059ce0387b1f6420612861142a7ebf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Fri, 24 Jul 2009 17:46:23 +0200 Subject: [PATCH] Modified batch mode to release memory of the modules. Used std::auto_ptr to work well with exceptions. --- batch.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/batch.cpp b/batch.cpp index cca2e5a..08f37ce 100644 --- a/batch.cpp +++ b/batch.cpp @@ -1,7 +1,8 @@ #include "headers.h" #include "imageUtil.h" -#include // cout and cerr streams +#include // cout and cerr streams +#include // auto_ptr (because of exceptions) #include #include @@ -17,7 +18,7 @@ inline QString tr(const char *str) { return QObject::tr(str); } /** Decodes a fractal image into a bitmap image */ void decodeFile(const char *inpName,QString outName) { - IRoot *root= IRoot::compatiblePrototype().clone(Module::ShallowCopy); + auto_ptr root( IRoot::compatiblePrototype().clone(Module::ShallowCopy) ); if ( !root->fromFile(inpName) ) throw tr("Error while reading file \"%1\"") .arg(inpName); root->decodeAct(MTypes::Clear); @@ -37,9 +38,9 @@ void encodeFile(const char *inpName,QString outName,const char *confName=0) { QTime time; time.start(); -// configure the module tree - IRoot *root= IRoot::compatiblePrototype() - .clone( confName ? Module::ShallowCopy : Module::DeepCopy ); +// configure the module tree, using auto_ptr to release memory on exception + Module::CloneMethod clMethod= confName ? Module::ShallowCopy : Module::DeepCopy; + auto_ptr root( IRoot::compatiblePrototype().clone(clMethod) ); if (confName) { if ( !root->allSettingsFromFile(confName) ) throw tr("Error while reading configuration file \"%1\"") .arg(confName); @@ -155,11 +156,8 @@ int batchRun(const vector &names) { break; case FileClassifier::Directory: // the output is a directory for (int inputID=inpStart; inputID