Practical memory checking with Dr. Memory

Derek Bruening, Qin Zhao
2011 International Symposium on Code Generation and Optimization (CGO 2011)  
Memory corruption, reading uninitialized memory, using freed memory, and other memory-related errors are among the most difficult programming bugs to identify and fix due to the delay and non-determinism linking the error to an observable symptom. Dedicated memory checking tools are invaluable for finding these errors. However, such tools are difficult to build, and because they must monitor all memory accesses by the application, they incur significant overhead. Accuracy is another challenge:
more » ... emory errors are not always straightforward to identify, and numerous false positive error reports can make a tool unusable. A third obstacle to creating such a tool is that it depends on low-level operating system and architectural details, making it difficult to port to other platforms and difficult to target proprietary systems like Windows. This paper presents Dr. Memory, a memory checking tool that operates on both Windows and Linux applications. Dr. Memory handles the complex and not fully documented Windows environment, and avoids reporting false positive memory leaks that plague traditional leak locating algorithms. Dr. Memory employs efficient instrumentation techniques; a direct comparison with the state-of-the-art Valgrind Memcheck tool reveals that Dr. Memory is twice as fast as Memcheck on average and up to four times faster on individual benchmarks. This paper's contributions include: • We describe the design for a complete memory checking tool that supports both Windows and Linux. • We enumerate possible function wrapping approaches and present a wrapping technique that is transparent and handles mutual recursion, tailcalls, and layered functions. • We present a novel technique for identifying and delimiting stack usage within heap memory. • We categorize the sources of false positives in
doi:10.1109/cgo.2011.5764689 dblp:conf/cgo/BrueningZ11 fatcat:eiduvwwc3vhuzkrk2qu64t3dwy