A More Complex Application in Software

Generate QR Code JIS X 0510 in Software A More Complex Application
A More Complex Application
Draw QR Code In Visual C#
Using Barcode creator for VS .NET Control to generate, create Quick Response Code image in VS .NET applications.
If you can track down a handle leak based on only knowing the type of the handle being leaked, consider yourself lucky (or a very skilled code reviewer) Most of the time, further diagnostics is required The previous sample shows how you can go about analyzing a fairly simple handle leak and what you can do to get to the bottom of it Now it s time to look at yet another leaky application with added complexity The key difference between the last leaky application and this one is that it no longer leaks handles systematically; rather, the occurrence of the leak is sporadic and, at first sight, random The basic architecture is the same; there is a client application and a server application (implemented
Making QR Code JIS X 0510 In .NET
Using Barcode creator for ASP.NET Control to generate, create QR Code JIS X 0510 image in ASP.NET applications.
9 RESOURCE LEAKS
Paint QR Code 2d Barcode In .NET
Using Barcode printer for .NET Control to generate, create QR Code 2d barcode image in .NET framework applications.
9
Create QR Code JIS X 0510 In VB.NET
Using Barcode maker for .NET Control to generate, create Denso QR Bar Code image in .NET framework applications.
Resource Leaks
Generating Barcode In .NET
Using Barcode encoder for ASP.NET Control to generate, create bar code image in ASP.NET applications.
as a static library for simplicity sake) The server exposes a set of functions that enable the client to get security-related information about the caller, such as the token privilege count, the group count, and the security indentifier (SID) The client application is called 09hleakexe and can be found in the following location: Source code: C:\AWD\9\HLeak\Client and C:\AWD\9\HLeak\Server Binary: C:\AWDBIN\WinXPx86chk\09hleakexe The 09hleakexe binary allows for the following command-line arguments:
ECC200 Creation In .NET
Using Barcode encoder for ASP.NET Control to generate, create Data Matrix image in ASP.NET applications.
C:\AWDBIN\WinXPx86chk\09hleakexe /t:<num_threads> /i:<iterations_per_thread> /s:<sleep_time_per_iteration>
Bar Code Generation In C#
Using Barcode maker for .NET framework Control to generate, create barcode image in .NET applications.
/t:<num_threads>
Data Matrix ECC200 Printer In Visual Basic .NET
Using Barcode printer for Visual Studio .NET Control to generate, create ECC200 image in .NET applications.
Specifies the number of concurrent threads that the client uses when invoking operations on the server
Recognizing Code 39 In VS .NET
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
/i:<iterations_per_thread>
Barcode Drawer In Visual Studio .NET
Using Barcode generator for Visual Studio .NET Control to generate, create barcode image in Visual Studio .NET applications.
Specifies the number of operations that will be performed by each thread
Painting GS1 - 12 In Java
Using Barcode creation for Java Control to generate, create UPC Symbol image in Java applications.
/s:<sleep_time_per_iteration>
Paint Bar Code In Java
Using Barcode generator for Java Control to generate, create bar code image in Java applications.
Specifies the number of seconds to wait between each operation in each thread Once again, for the sake of simplicity, the client stress application links directly against a static library that represents the server Let s begin by running the application once, specifying that we want 5 threads, 5 iterations per thread, and 0 second sleep time:
Make UCC.EAN - 128 In VS .NET
Using Barcode printer for ASP.NET Control to generate, create EAN128 image in ASP.NET applications.
C:\AWDBIN\WinXPx86chk\09hleakexe /t:5 /i:5 /s:0
Barcode Printer In VB.NET
Using Barcode generator for .NET framework Control to generate, create barcode image in .NET framework applications.
Let the application run and, at the same time, watch the handle consumption in Process Explorer Figure 98 shows the result of the run in Process Explorer view As you can see, our handle count has gone from approximately 8 at the start of the application run to 13 (don t worry if your handle count is different; it s all part of the exercise) at the end of the run Not a good sign Now, let s run it again, with the same parameters Figure 99 shows the results in Process Explorer view
Print EAN / UCC - 13 In VS .NET
Using Barcode drawer for .NET Control to generate, create GS1 128 image in .NET framework applications.
Handle Leaks
Code 128 Code Set B Recognizer In .NET Framework
Using Barcode decoder for .NET framework Control to read, scan read, scan image in VS .NET applications.
9 RESOURCE LEAKS
UPC - 13 Reader In VS .NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in .NET applications.
9
Scanning ECC200 In VS .NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in .NET applications.
Resource Leaks
Drawing EAN / UCC - 14 In Java
Using Barcode generator for Java Control to generate, create UCC-128 image in Java applications.
This time, we ended up with 23 handles, even though we used the same input If you keep running the application, you will notice that there isn t any real pattern to the leak The only observation that seems to hold true is that if we increase the number of threads and iterations, we see a bigger leak For example, running with the following command line
Drawing ANSI/AIM Code 39 In Java
Using Barcode maker for Java Control to generate, create USS Code 39 image in Java applications.
C:\AWDBIN\WinXPx86chk\09hleakexe /t:20 /i:10 /s:0
the handle count goes up dramatically, as shown in Figure 910
We know that the client application uses the server in a multithreaded fashion and that it calls various functions on the server From the Process Explorer view, we can also see that it appears to be leaking token handles How do we go about tracking down this type of sporadic handle leak The answer is step 4 in our leak detection process: making use of leak detection tools For this exercise, try not to look at the code ahead of time We are going to show you some of the most important tools of tracking down these types of unpredictable issues By unpredictable, we mean leaks that do not reproduce consistently and cannot (reasonably) be tracked down via simple code reviews We will skip steps 1 3 in our five-step
Handle Leaks
leak detection process because we already know that there is a handle leak We also assume that it cannot be easily spotted by a simple code review
Step 4: Make Use of Resource Leak Detection Tools
Okay, we have a sporadic and apparently random handle leak on our hands Although this might seem like a doomsday scenario, there is some good news As odd as it might seem, the good news is that the leak appears to surface every time the application is run; it just does not reproduce with the same number of handles being leaked Why is that good news Because it is a prime opportunity to leverage an extremely powerful extension command called !htrace that can help you detect where the leak is occurring Htrace stands for handle trace, and the basic idea behind the command is to enable the operating system to track all calls (with associated stack traces) that result in handles being opened and closed When a leak has been identified, you can then use the !htrace extension command to display all the stack traces in the debugger After all stack traces are shown, you can track down sporadic handle leaks in a much easier fashion Let s take a look at the available options for the !htrace extension command First, start our leaky application (with the same command-line options as before):