O'Reilly logo

Memory Dump Analysis Anthology, Volume 8a by Dmitry Vostokov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Invalid Handle (Managed Space)

We recently encountered Invalid Handle (Volume 2, page 269) pattern in the context of .NET program execution. We decided to model it and wrote a small C# program:

 namespace SafeHandle                                                                 
 {                                                                                    
     class Program                                                                    
     {                                                                                
         static void Main(string[] args)                                              
         {                                                                            
             SafeFileHandle hFile =                                                   
                  new SafeFileHandle(new IntPtr(0xDEAD), true);                       
             Console.WriteLine("About to close");                                     
             Console.ReadKey();                                                       
         }                                                                            
     }                                                                                
 }                                                                                    

Of course, when we execute it nothing happens. Invalid handles are ignored by default. However, to change the behavior we enabled “Enable close exception” in glags.exe:

images

Moreover, if we run it we get this Managed Stack Trace (Volume 6, page 115):

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required