summaryrefslogtreecommitdiffstats
path: root/tools/slang-generate/main.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-08-04 11:57:45 -0700
committerGitHub <noreply@github.com>2020-08-04 11:57:45 -0700
commitde309d939199ec3fef1dacf23b502b7f209e37a1 (patch)
treeacaf3f814ab6069e4b9a84c215c83f4077e82672 /tools/slang-generate/main.cpp
parent00b1fe044840e7818c6c9bcd4c42d4baafd5b78a (diff)
Fix leaks in slang-generate (#1472)
Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'tools/slang-generate/main.cpp')
-rw-r--r--tools/slang-generate/main.cpp29
1 files 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<SourceFile*> gSourceFiles;
+List<RefPtr<SourceFile>> gSourceFiles;
int main(
int argc,