From 6380e5d7ea7cce0934b394c0de02813a9ceff763 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Mon, 12 Oct 2015 15:01:21 +0300 Subject: [PATCH] Called Marshal.FreeHGlobal only if the instance was created by Marshal.AllocHGlobal. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CSharp/CSharpTextTemplate.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index e61ab045..6c48b367 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -1867,7 +1867,8 @@ namespace CppSharp.Generators.CSharp } } - WriteLine("Marshal.FreeHGlobal({0});", Helpers.InstanceIdentifier); + WriteLine("if ({0})", Helpers.OwnsNativeInstanceIdentifier); + WriteLineIndent("Marshal.FreeHGlobal({0});", Helpers.InstanceIdentifier); WriteCloseBraceIndent(); PopBlock(NewLineKind.BeforeNextBlock);