LocalAllocHandle.cs 892 B

1234567891011121314151617181920212223242526
  1. // Copyright (c) .NET Foundation. All rights reserved.
  2. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  3. using System;
  4. using System.Runtime.InteropServices;
  5. using Microsoft.Win32.SafeHandles;
  6. namespace Microsoft.AspNetCore.Cryptography.SafeHandles
  7. {
  8. /// <summary>
  9. /// Represents a handle returned by LocalAlloc.
  10. /// </summary>
  11. internal class LocalAllocHandle : SafeHandleZeroOrMinusOneIsInvalid
  12. {
  13. // Called by P/Invoke when returning SafeHandles
  14. protected LocalAllocHandle()
  15. : base(ownsHandle: true) { }
  16. // Do not provide a finalizer - SafeHandle's critical finalizer will call ReleaseHandle for you.
  17. protected override bool ReleaseHandle()
  18. {
  19. Marshal.FreeHGlobal(handle); // actually calls LocalFree
  20. return true;
  21. }
  22. }
  23. }