1 //------------------------------------------------------------------------------
2 // <copyright file="HeapAllocHandle.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
6 
7 namespace System.Web.Util {
8     using System;
9     using System.Diagnostics.CodeAnalysis;
10     using Microsoft.Win32.SafeHandles;
11 
12     internal class HeapAllocHandle : SafeHandleZeroOrMinusOneIsInvalid {
13         [SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources", Justification = @"This pointer is valid for the lifetime of the process; never needs to be released.")]
14         private static readonly IntPtr ProcessHeap = UnsafeNativeMethods.GetProcessHeap();
15 
16         // Called by P/Invoke when returning SafeHandles
HeapAllocHandle()17         protected HeapAllocHandle()
18             : base(ownsHandle: true) {
19         }
20 
21         // Do not provide a finalizer - SafeHandle's critical finalizer will call ReleaseHandle for you.
ReleaseHandle()22         protected override bool ReleaseHandle() {
23             return UnsafeNativeMethods.HeapFree(ProcessHeap, 0, handle);
24         }
25     }
26 }
27