While we are talking about dynamic memory allocation and de-allocation, a useful trick at times is to wrap your mallocator with a bit of code so that you can program it to fail after, say, n allocations, or on a random basis. In a testing context, this can help you systematically explore the set of possible allocation failures to see if the code handles them as expected.