I did it once, but it was not so simple. Now I do not have access to this code, but here is the idea:
I used the debugging features that Mike B was talking about (by the way, they only work in Debug).
The test drive ran all the tests twice, because during the first run, memory is allocated for global variables. The second time, the total number of allocated blocks was checked before and after each test (I think you can do this in setUp () and tearDown ()). If the number was different, it meant a memory leak, and the test failed with the appropriate message. Of course, if the test itself fails, you should save its error message. Now, to find the leak, I had to read the allocation number of the last distribution block using pBlockHeader, and then set a breakpoint on it using _ CrtSetBreakAlloc and run it again.
More about this here: http://levsblog.wordpress.com/2008/10/31/unit-testing-memory-leaks/
source share