From 648e47570d3f08b48ccc3d4ffd4e9ebda0a0e5bc Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Wed, 29 Jan 2014 23:43:24 +0200 Subject: [PATCH] Checked for symbols before calling destructors. Signed-off-by: Dimitar Dobrev --- .../Generators/CSharp/CSharpTextTemplate.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index a70aae88..a964d25d 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -1854,9 +1854,19 @@ namespace CppSharp.Generators.CSharp if (ShouldGenerateClassNativeField(@class)) { var dtor = @class.Methods.FirstOrDefault(method => method.IsDestructor); - if (dtor != null && @class.HasNonTrivialDestructor) - WriteLine("Internal.{0}({1});", GetFunctionNativeIdentifier(dtor), - Helpers.InstanceIdentifier); + if (dtor != null) + { + if (dtor.Access != AccessSpecifier.Private && @class.HasNonTrivialDestructor) + { + NativeLibrary library; + if (!Options.CheckSymbols || + Driver.Symbols.FindLibraryBySymbol(dtor.Mangled, out library)) + { + WriteLine("Internal.{0}({1});", GetFunctionNativeIdentifier(dtor), + Helpers.InstanceIdentifier); + } + } + } WriteLine("Marshal.FreeHGlobal({0});", Helpers.InstanceIdentifier); }