From de309d939199ec3fef1dacf23b502b7f209e37a1 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 4 Aug 2020 11:57:45 -0700 Subject: Fix leaks in slang-generate (#1472) Co-authored-by: Tim Foley --- tools/slang-generate/main.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/tools/slang-generate/main.cpp b/tools/slang-generate/main.cpp index 5fca7c21a..700c1bb21 100644 --- a/tools/slang-generate/main.cpp +++ b/tools/slang-generate/main.cpp @@ -30,18 +30,33 @@ struct Node StringSpan span; // The body of this node for other flavors - Node* body; + Node* body = nullptr; // The next node in the document - Node* next; + Node* next = nullptr; + + Node() = default; + ~Node() + { + if (body) delete body; + if (next) delete next; + } }; // Information about a source file -struct SourceFile +struct SourceFile : public RefObject { String inputPath; - StringSpan text; - Node* node; + StringSpan text; + Node* node = nullptr; + SourceFile() = default; + ~SourceFile() + { + if (text.begin()) + free((void*)text.begin()); + if (node) + delete node; + } }; void addNode( @@ -795,10 +810,12 @@ SourceFile* parseSourceFile(const String& path) Node* node = parseSourceFile(sourceFile); sourceFile->node = node; + + fclose(inputStream); return sourceFile; } -List gSourceFiles; +List> gSourceFiles; int main( int argc, -- cgit v1.2.3