From de3cbbaf167d2190e99127a2577b5d0eed1a7731 Mon Sep 17 00:00:00 2001 From: Rejean Loyer Date: Wed, 27 Jul 2016 00:55:35 -0400 Subject: [PATCH] extras/FileSystemIterator: fix OnInit work work properly. fix memory leak. --- extras/FileSystemIterator.ec | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/extras/FileSystemIterator.ec b/extras/FileSystemIterator.ec index 31b4e16..ba65bb8 100644 --- a/extras/FileSystemIterator.ec +++ b/extras/FileSystemIterator.ec @@ -26,17 +26,13 @@ public: { StackFrame frame; - if(OnInit(startPath)) - { - frame = stack.firstIterator.data; - } - else - { - frame = StackFrame { }; - stack.Add(frame); - frame.path = CopyString(startPath); - frame.listing = FileListing { startPath, extensions = extensions }; // there should be a sorted = true/false - } + if(!OnInit(startPath)) + return; + + frame = StackFrame { }; + stack.Add(frame); + frame.path = CopyString(startPath); + frame.listing = FileListing { startPath, extensions = extensions }; // there should be a sorted = true/false if(iterateStartPath) { @@ -74,6 +70,7 @@ public: StackFrame parentFrame = stack.count > 1 ? stack[stack.count - 2] : null; OutFolder(parentFrame ? parentFrame.listing.path : startPath, !parentFrame); stack.lastIterator.Remove(); + delete frame; if(stack.count) frame = stack.lastIterator.data; else @@ -90,7 +87,7 @@ public: virtual bool OnInit(const char * startPath) { - return false; + return true; } virtual bool OnFile(const char * filePath) -- 1.8.3.1