From a2177c9b8b8428dd536fe08c6aaddb644324631a Mon Sep 17 00:00:00 2001 From: kichik Date: Sat, 22 Oct 2005 13:40:52 +0000 Subject: [PATCH] dir_readers' memory now freed by boost::scoped_ptr git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4357 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/Plugins.cpp | 6 +++--- Source/script.cpp | 32 ++++++++++---------------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/Source/Plugins.cpp b/Source/Plugins.cpp index a050a469..8d9e3336 100644 --- a/Source/Plugins.cpp +++ b/Source/Plugins.cpp @@ -16,13 +16,15 @@ # include #endif +#include "boost/scoped_ptr.hpp" + using namespace std; extern FILE *g_output; void Plugins::FindCommands(const string &path, bool displayInfo) { - dir_reader *dr = new_dir_reader(); + boost::scoped_ptr dr( new_dir_reader() ); dr->read(path); dir_reader::iterator files_itr = dr->files().begin(); @@ -35,8 +37,6 @@ void Plugins::FindCommands(const string &path, bool displayInfo) const string plugin = path + PLATFORM_PATH_SEPARATOR_C + *files_itr; GetExports(plugin, displayInfo); } - - delete dr; } void Plugins::GetExports(const string &pathToDll, bool displayInfo) diff --git a/Source/script.cpp b/Source/script.cpp index f76b7b2a..0260b9b5 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -13,6 +13,7 @@ #include #include #include +#include "boost/scoped_ptr.hpp" using namespace std; @@ -2761,7 +2762,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) #endif // search working directory - dir_reader *dr = new_dir_reader(); + boost::scoped_ptr dr( new_dir_reader() ); dr->read(dir); dir_reader::iterator files_itr = dr->files().begin(); @@ -2774,15 +2775,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) string incfile = basedir + *files_itr; if (includeScript((char *) incfile.c_str()) != PS_OK) { - delete dr; return PS_ERROR; } included++; } - delete dr; - if (included) return PS_OK; @@ -2793,7 +2791,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) for (int i = 0; i < incdirs; i++, incdir += strlen(incdir) + 1) { string curincdir = string(incdir) + PLATFORM_PATH_SEPARATOR_STR + dir; - dir_reader *dr = new_dir_reader(); + boost::scoped_ptr dr( new_dir_reader() ); dr->read(curincdir); files_itr = dr->files().begin(); @@ -2806,14 +2804,12 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) string incfile = string(incdir) + PLATFORM_PATH_SEPARATOR_STR + basedir + *files_itr; if (includeScript((char *) incfile.c_str()) != PS_OK) { - delete dr; return PS_ERROR; } included++; } - delete dr; } // nothing found @@ -5708,25 +5704,24 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int *total spec = "*"; } - dir_reader *dr = new_dir_reader(); - dr->exclude(excluded); - dr->read(dir); - - dir_reader::iterator files_itr = dr->files().begin(); - dir_reader::iterator files_end = dr->files().end(); - if (basedir == "") { dir_created = true; if (recurse) { // save $OUTDIR into $_OUTDIR [StrCpy $_OUTDIR $OUTDIR] if (add_entry_direct(EW_ASSIGNVAR, m_UserVarNames.get("_OUTDIR"), add_string("$OUTDIR")) != PS_OK) { - delete dr; return PS_ERROR; } } } + boost::scoped_ptr dr( new_dir_reader() ); + dr->exclude(excluded); + dr->read(dir); + + dir_reader::iterator files_itr = dr->files().begin(); + dir_reader::iterator files_end = dr->files().end(); + // add files in the current directory for (; files_itr != files_end; files_itr++) { if (!dir_reader::matches(*files_itr, spec)) @@ -5736,7 +5731,6 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int *total SCRIPT_MSG("%sFile: Descending to: \"%s\"\n", generatecode ? "" : "Reserve", dir.c_str()); if (do_add_file_create_dir(dir, basedir, attrib) != PS_OK) { - delete dr; return PS_ERROR; } @@ -5744,7 +5738,6 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int *total } if (add_file(dir, *files_itr, attrib, name_override, generatecode, data_handle) != PS_OK) { - delete dr; return PS_ERROR; } @@ -5776,7 +5769,6 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int *total SCRIPT_MSG("%sFile: Descending to: \"%s\"\n", generatecode ? "" : "Reserve", new_spec.c_str()); if (do_add_file_create_dir(*dirs_itr, new_dir, attrib) != PS_OK) { - delete dr; return PS_ERROR; } @@ -5787,7 +5779,6 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int *total int res = do_add_file(new_spec_c, attrib, 1, total_files, NULL, generatecode, NULL, excluded, new_dir, created); if (res != PS_OK) { - delete dr; return PS_ERROR; } } @@ -5797,14 +5788,11 @@ int CEXEBuild::do_add_file(const char *lgss, int attrib, int recurse, int *total // restore $OUTDIR from $_OUTDIR [SetOutPath $_OUTDIR] if (add_entry_direct(EW_CREATEDIR, add_string("$_OUTDIR"), 1) != PS_OK) { - delete dr; return PS_ERROR; } } } - delete dr; - return PS_OK; }