From 6e5a8e835d32a66ab3511cb477d952b7e31135b0 Mon Sep 17 00:00:00 2001
From: Dimitar Dobrev <dpldobrev@protonmail.com>
Date: Wed, 16 Dec 2015 22:45:52 +0200
Subject: [PATCH] Fixed a crash when wrapping more than one header.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
---
 src/Core/Parser/Parser.cs | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/Core/Parser/Parser.cs b/src/Core/Parser/Parser.cs
index 37521c42..456ba681 100644
--- a/src/Core/Parser/Parser.cs
+++ b/src/Core/Parser/Parser.cs
@@ -1,4 +1,6 @@
 using System;
+using System.Collections.Generic;
+using System.Linq;
 using CppSharp.AST;
 using CppSharp.Parser;
 using ASTContext = CppSharp.Parser.AST.ASTContext;
@@ -48,14 +50,16 @@ namespace CppSharp
         /// <summary>
         /// Parses a C++ source file to a translation unit.
         /// </summary>
-        public void ParseSourceFile(SourceFile file)
+        public ParserResult ParseSourceFile(SourceFile file)
         {
             var options = file.Options;
             options.ASTContext = ASTContext;
             options.FileName = file.Path;
 
-            using (var result = Parser.ClangParser.ParseHeader(options))
-                SourceParsed(file, result);
+            var result = Parser.ClangParser.ParseHeader(options);
+            SourceParsed(file, result);
+
+            return result;
         }
 
         /// <summary>
@@ -65,9 +69,9 @@ namespace CppSharp
         {
             // TODO: Search for cached AST trees on disk
             // TODO: Do multi-threaded parsing of source files
-
-            foreach (var source in project.Sources)
-                ParseSourceFile(source);
+            
+            foreach (var parserResult in project.Sources.Select(s => ParseSourceFile(s)).ToList())
+                parserResult.Dispose();
         }
 
         /// <summary>