Click here to Skip to main content
15,895,709 members
Articles / Desktop Programming / ATL
Article

Software Verification's Memory Validator

23 May 2003CPOL 454.6K   37   69
Memory Validator is an automatic runtime error detection software tool for Windows applications.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

This is the first in a series of showcase reviews for our sponsors at CodeProject. These reviews are intended to provide you with information on products and services that we consider useful and of value to developers. They also allow you to discuss a product and interact with the manufacture or provider on a one-to-one basis.

Software Verification Logo

Faster leak detection, better analysis.

A common problem in software development is the problem of detecting and fixing memory leaks, handle leaks and memory corruption. Performing this task without the aid of software tools can be a slow and time consuming task, often resulting in a lot of wasted time as avenues of investigation turn out to be dead ends and the search for the bug turns to a different area of the software. This problem gets harder to solve and harder to manage the larger the codebase being worked on.

Software tools are often employed to solve this problem. Selection of an appropriate software tool requires that the software tool provides various features.

  • The software tool must not change the behaviour of the program being monitored.
  • The software tool must have as little impact as possible on the performance (both speed and reliability) of the program being monitored.
  • The software tool should provide many ways of interrogating the collected data as possible so that end users can look at a given problem from a number of angles.
  • The software tool should be configurable so that the user has a choice of tailoring the behaviour of the tool. This allows users to maximise the speed at which data collection occurs whilst collecting the data required, without collecting data that is not needed to investigate the bug under investigation.
  • If the program being monitored crashes, the software tool must not crash.
  • The software tool must be reliable, and in the event that the software tool crashes, it must not crash the program being monitored.
  • The software tool should also be capable of being used in a regression testing role, so that Quality Assurance departments can produce defect reports to direct software maintenance with a minimum of effort.

Memory Validator from Software Verification satisfies all of the criteria above.

Memory Validator is an automatic runtime error detection software tool for Windows applications. Memory Validator detects common problems associated with the use of dynamic memory allocation, Windows resources and handle management. Such problems include detecting memory leaks, resource leaks, handle leaks, incorrect allocations, buffer overruns, buffer under-runs, corrupted data, reference counting errors and un-initialised data. Memory Validator also provides support for detecting hotspots in the code where large amounts of memory or handles are allocated, reallocated or deallocated.

No special preparation of your program is required to use Memory Validator, simply use Memory Validator to launch your program and Memory Validator monitors your program's behaviour. You don't need to recompile or relink your program*. When your program performs an error, such as a double deallocation of memory or a buffer overwrite, Memory Validator tells you, showing you the error, the callstack for the error and the source code for the error. When you close your program, Memory Validator displays all the memory that has leaked. Each type of data displayed by Memory Validator is colour coded so that it is easy to identify. Powerful filtering mechanisms allow you to simplify the data that is collected and which data is displayed, so that you can concentrate on one particular error at a time.

expanded view of memory allocations

Memory Validator provides support for more than just the C runtime heap, you can also monitor the Win32 HeapAlloc(), LocalAlloc(), GlobalAlloc() and VirtualAlloc() functions as well as custom heap managers that you have written yourself. If you are using a reference counting scheme in your software, you will have come across the problem of out-of-sync reference counts and trying to determine where the counts go out of sync. Memory Validator provides support for tracking this type of error.

There are occasions when the program you want to monitor is already running, or the program you want to monitor is started by another program. Say for example your program is a COM server that starts when a document is embedded in a web-page. Memory Validator provides support for attaching to your server at the time the web-page requests the COM object. This can be very useful for identifying double frees or memory leaks that only occur when the program is run as a COM server, and not as a standalone program. If the program you want to monitor is already running, you can attach to the program with Memory Validator and monitor the program from this point to the program's conclusion.

Powerful analysis capabilities allow you to find memory allocations by address, near an address, allocations that hold pointers that point to an address (useful for determining which objects are still referencing the memory allocation you are examining) and which allocations are pointed to by pointers in the allocation you are examining (useful for determining which objects this object is using). You can find allocations by object type, or by the full or partial name of a function in the callstack of the allocations, or the full or partial name of the function at the top of the callstack in the name. You can find memory allocations by filename, dll name, address range, page range, size range, allocation id number (debug only), allocation heap and allocation type (alloc, realloc, free). On the analysis page, you can select an allocation and then ask to see all related objects. Related objects are objects of the same type, objects previously allocated at this address (good for analysing what may have happened after a delete that happened too early), other objects of the same type, other objects allocated in the same class, file or module, and so forth. Based on the results of an analysis you can select one, some or all of the results, and then repeat the query on these objects to drill through an entire allocation chain, seeing which object was related to which. This functionality can be very useful in finding the cause of very subtle bugs, which are often caused hundreds or thousands of allocations before the bug results in a visible error in the program.

Memory Validator provides a visual presentation of the current number of allocations for each type of memory and the total number of active handles, a visual presentation of the virtual memory map, with different colours for each type of memory use. This view can be very useful for determining why requests for large blocks of memory fail. Your computer may report X bytes free, but when you look at the memory map, you can see the memory is in 20 different blocks that are not contiguous.

Memory Validator provides support for detecting memory allocation hotspots. Once identified, the memory allocation and deallocation strategy can be modified to improve the way in which memory is consumed, thus putting less strain on the memory allocator, and so improving program performance.

Memory Validator provides support for ensuring that all places in the program that can allocated, reallocate or deallocate memory have been visited during test sessions. This support is provided by the Coverage window. The quality assurance team can use these metrics to ensure that an application has been thoroughly tested prior to launch.

Memory Validator provides support for regression testing. Regression testing can be performed in attended and unattended modes. The regression testing allows you to compare a baseline session with a session representing the test just performed. When the two sessions are compared you can see where you are making improvements in memory leak fixing and where you are making regressions in memory leak detection. You can export these results in HTML and XML formats for further processing. Unattended regression testing allows you to run Memory Validator from a command line or batch file, start the program of your choice, monitor for memory leaks, compare the resulting session with a baseline for the test, produce the regression test report, save the session and export the results in HTML and XML. For Quality Assurance departments with can use the regression testing facilities with their overnight test suites to provide at-a-glance reports the next day of which parts of the software are improving or regressing. Feedback from this can dramatically improve the error detection rate from the overnight/rolling software build. The XML reports can be further processed to produce reports which can be put on the internal bug report web server, or forwarded to management for further action.

Memory Validator is very configurable. The default options allow you to make immediate progress in tackling common problems. For more comprehensive error detection you can enable more options, or just the options related to your bugs. For example, if you are interested in tracking handle leaks, you don't want your software tool to track memory leaks - that would be a waste of time and effort. With Memory Validator, you can do just that, turn off the memory leak tracking and only track the handles. Or, say you wanted to track memory leaks, but only for the HeapAlloc(), HeapReAlloc() and HeapFree() functions, and not the C runtime. Turn off the CRT tracking, turn on the HeapAlloc() tracking and start your program. These are just two examples of improving the speed and ease at which you can find bugs with Memory Validator. The configurability goes further than this, you can, if so desired, go down to the function level to specify which functions should and should not be monitored.

Typical users of Memory Validator are software developers that don't want to spend a long time trying to identify what is causing the memory corruption, double delete, or memory leaks in their program. Quality Assurance departments will be interested in the support for unattended regression testing. Management will be pleased that data exported from Memory Validator can be turned in reports indicating improvements and regressions thanks to the support for XML export.

For professionals wanting to identify and fix hard to find memory leaks, resource leaks and memory corruptions in a fast and efficient manner, Memory Validator is a must have tool.

For sales and information on Memory Validator click here.

* To use the Memory Validator API, you need to link to a specific library file. This change will be required once only. You may need to change compiler settings to use the dynamic C runtime library if you are using the static C runtime library. This change will be required once only.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United Kingdom United Kingdom
Commercial Software developer.

Started out writing 6502 assembly language games for C64 (for a bet, I won, he never paid). I wrote 27 games in total.

After suffering and recovering Repetitive Strain Injury in 1994 I went independent and have consulted for BT, Aethos (GSM consultancy before sold to Logica), DERA, BT (again), Cloudworld (computer use for blind people), Solidworks (fastest growing company in history of CAD, ever).

I am currently working for Software Verification Limited, producing software tools for software engineers on the Win32 and .net platforms, targetting C++, C, C# and Java.


Comments and Discussions

 
GeneralRe: Memory Validator 2.10 Pin
Stephen Kellett24-May-02 5:04
Stephen Kellett24-May-02 5:04 
GeneralRe: Memory Validator 2.10 Pin
Mike Osbahr24-May-02 11:06
Mike Osbahr24-May-02 11:06 
GeneralRe: Memory Validator 2.10 Pin
Stephen Kellett24-May-02 21:11
Stephen Kellett24-May-02 21:11 
GeneralRe: Memory Validator 2.10 Pin
Stephen Kellett28-May-02 14:52
Stephen Kellett28-May-02 14:52 
GeneralGood summary Pin
Vivek Rajan18-May-02 8:10
Vivek Rajan18-May-02 8:10 
GeneralRe: Good summary Pin
Stephen Kellett18-May-02 10:58
Stephen Kellett18-May-02 10:58 
GeneralGreat addition and a question Pin
Brent Corkum18-May-02 6:25
Brent Corkum18-May-02 6:25 
GeneralRe: Great addition and a question Pin
Stephen Kellett18-May-02 7:04
Stephen Kellett18-May-02 7:04 
Hi Brent,

I can't comment directly on BoundsChecker as I have never used it. NuMega declined to give me an evaluation license when they found out who I was. They can have an evaluation of Memory Validator though. I found their website to be rather uninformative as to what the product can and cannot do. However you can find a brief feature list for Memory Validator here

All answers given here are based on what people have told me and what I have been able to determine from their product literature/website. Its all from memory, so please correct me if I am wrong.

From what I understand, Boundschecker requires you to recompile and relink your product (this may have changed), where as Memory Validator doesn't. For anything other than trivial projects, this is going to be a serious time waster.

Memory Validator is 100% accurate at detecting memory leaks, based on the testing we have done. If Memory Validator sees the allocation (i.e. all allocations after Memory Validator has attached to your program), then Memory Validator will track the deallocations until the program shuts down (including until after MSVCRT(D).DLL has unloaded deep inside ExitProcess). So we see all CRT deallocations during the shutdown process. Memory Validator tracks all memory allocation types, I'm not sure that BoundsChecker does this.

Memory Validator tracks handle allocations. Memory Validator can detect uninitialised memory and can detect double deletes and buffer access errors. I don't know if BoundsChecker does this.

I understand BoundsChecker checks Win32 APIs for parameter validity. Memory Validator does not do this - it is not intended to.

Memory Validator provides many methods for querying the data you have collected - including historical data about memory that has been allocated and deallocated. I don't think there is any other product in this market that allows you to query this data to find data hotspots, or drill through the allocations to find references to objects that were deleted a long time before you thought they were.

However, if you want an interesting comparison, take the example application that ships with Memory Validator Evaluation. Edit teststak.cpp to enable the slow startup simulation and set to do 1,000,000 allocations. On a 1Ghz Athlon with 512Mb, this takes 58 seconds to start the application with Memory Validator tracking all allocations. Then close the demo. Memory Validator will detect the application has closed and display the 1,000,000 leaked items to you. Try this with BoundsChecker. If you do this with boundschecker can you examine all the allocations, reallocations deallocations that occurred within the lifetime of the program (even though the program has now gone?). You can with Memory Validator.

Want to export this data for a regression test report, or the basis for a Memory leak SPR? HTML or XML? No problem.

Memory Validator provides support for regression testing, BoundsChecker, to my knowledge does not.

Memory Validator also provides support for instrumenting and tracking user defined heaps and referenced counted objects. I don't know of any other memory leak tracking tool that can do this.

Finally, we aim to supply bug fixes and responses to problems on a timely basis. One of our customers told us of a product they were using that only ships bugs fixes once every six months, and often state that there is no gaurantee that your issue will be fixed. That is why they are now a customer of Software Verification. For them it was a major issue. So they changed.

Since April 15, 2002 we have shipped 9 minor bug fixes and upgrades and performance improvements, based on user feedback, internal research, and bugs found in internal testing and future product development (*). We have some more changes that will make it into the product next week.

For Example: Last week, a user named Sein, on this web site, mentioned a problem with the VisualStudio.net symbolsnot being picked up, we had a fix posted to this website within hours (1 of which was spent installing the latest VisualStudio.net on a vanilla machine to reproduce the bug) and a new upload with the fix in it on the website, the same evening (we only do uploads in the evening).

(*) We'll be announcing a public beta next week of a new product for Win32.

If you have any further questions, please let me know.

Cheers

Stephen Kellett
--
Memory Validator. Faster Leak Detection, Better Analysis.
http://www.softwareverify.com

http://www.objmedia.demon.co.uk
GeneralRe: Great addition and a question Pin
Stephen Kellett18-May-02 7:20
Stephen Kellett18-May-02 7:20 
GeneralRe: Great addition and a question Pin
Brent Corkum20-May-02 12:12
Brent Corkum20-May-02 12:12 
GeneralRe: Great addition and a question Pin
Stephen Kellett20-May-02 13:58
Stephen Kellett20-May-02 13:58 
GeneralTell us about the RSI.... Pin
Christian Graus17-May-02 21:13
protectorChristian Graus17-May-02 21:13 
GeneralRe: Tell us about the RSI.... Pin
Stephen Kellett18-May-02 1:21
Stephen Kellett18-May-02 1:21 
GeneralMemory Validator V2.09 Pin
Stephen Kellett16-May-02 23:20
Stephen Kellett16-May-02 23:20 
GeneralRe: Memory Validator V2.09 Pin
17-May-02 19:46
suss17-May-02 19:46 
GeneralRe: Memory Validator V2.09 Pin
Stephen Kellett18-May-02 7:23
Stephen Kellett18-May-02 7:23 
Generalexcellent Pin
16-May-02 20:42
suss16-May-02 20:42 
GeneralRe: excellent Pin
Stephen Kellett16-May-02 23:13
Stephen Kellett16-May-02 23:13 
Generallooks like it has nice features, but.. Pin
16-May-02 3:28
suss16-May-02 3:28 
GeneralRe: looks like it has nice features, but.. Pin
Stephen Kellett16-May-02 4:36
Stephen Kellett16-May-02 4:36 
QuestionWhat is goin' on ? Pin
Armen Hakobyan15-May-02 21:53
professionalArmen Hakobyan15-May-02 21:53 
AnswerRe: What is goin' on ? Pin
Chris Losinger16-May-02 3:39
professionalChris Losinger16-May-02 3:39 
QuestionUnknown Section? Pin
James T. Johnson15-May-02 8:52
James T. Johnson15-May-02 8:52 
AnswerRe: Unknown Section? Pin
Chris Maunder15-May-02 16:14
cofounderChris Maunder15-May-02 16:14 
GeneralProduct Showcase == No Source Pin
Hans Dietrich15-May-02 6:10
mentorHans Dietrich15-May-02 6:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.