Browse Source

Added check for native pointer for null before calling a destructor and set it to null after (#843)

Fixes #808
pull/844/head
Mohit Mohta 8 years ago committed by Dimitar Dobrev
parent
commit
78c9a3e791
  1. 4
      src/Generator/Generators/CSharp/CSharpSources.cs

4
src/Generator/Generators/CSharp/CSharpSources.cs

@ -1859,6 +1859,9 @@ namespace CppSharp.Generators.CSharp @@ -1859,6 +1859,9 @@ namespace CppSharp.Generators.CSharp
// Use interfaces if any - derived types with a this class as a seconary base, must be compatible with the map
var @interface = @base.Namespace.Classes.Find(c => c.OriginalClass == @base);
WriteLine("if ({0} == IntPtr.Zero)", Helpers.InstanceIdentifier);
WriteLineIndent("return;");
// The local var must be of the exact type in the object map because of TryRemove
WriteLine("{0} {1};",
(@interface ?? (@base.IsAbstractImpl ? @base.BaseClass : @base)).Visit(TypePrinter),
@ -1907,6 +1910,7 @@ namespace CppSharp.Generators.CSharp @@ -1907,6 +1910,7 @@ namespace CppSharp.Generators.CSharp
WriteLine("if ({0})", Helpers.OwnsNativeInstanceIdentifier);
WriteLineIndent("Marshal.FreeHGlobal({0});", Helpers.InstanceIdentifier);
WriteLine("{0} = IntPtr.Zero;", Helpers.InstanceIdentifier);
WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
}

Loading…
Cancel
Save