1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>Comparison of Free Memory Checkers</title>
<link rel="start" type="text/html" href="http://www.cs.utexas.edu/%7Ejpmartin/index.html">
<link rel="up" type="text/html" href="http://www.cs.utexas.edu/%7Ejpmartin/resources.html">
<link rel="icon" type="image/png" href="http://www.cs.utexas.edu/%7Ejpmartin/longhorn_icon.png">
<link rel="styleSheet" href="memCheckers-Dateien/jpstyle.css" title="default stylesheet">
<link rel="Alternate StyleSheet" href="memCheckers-Dateien/boringstyle.css" title="alternate
(old-fashioned) stylesheet"></head><body>
<h1><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/index.html">Jean-Philippe Martin</a> |
<a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/resources.html">Resources</a> | Memory Checkers Comparison </h1>
<hr>
<p>
</p><h3>Memory Checkers</h3>
Memory checkers are debugging tools that help programmers find
improper use of pointers, typically memory leaks.
<p align="justify">
There are some freely available memory checkers. I ran a series of
very simple tests to determine what they can do. The <b>wrong</b>
series of tests contains code that makes pointer mistakes that are not
memory leaks, for example freeing a pointer twice, writing to
uninitialized memory or using delete instead of delete []. The
<b>leak</b> series of tests contains simple memory leaks,
i.e. pointers that are allocated but not released. The <b>ok</b>
series of tests contains programs that are correct and thus should not
cause the memory checker to output any alarm message.
</p>
<h3>C tests</h3>
(updated 3/10/2006)<p>
<table border="1">
<colgroup>
</colgroup><colgroup span="3">
</colgroup><colgroup span="2">
</colgroup><colgroup>
</colgroup><tbody><tr>
<th>Checker
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong1.c">wrong1.c</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong3.c">wrong3.c</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong6.c">wrong6.c</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong7.c">wrong7.c</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/leak1.c">leak1.c</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/leak2.c">leak2.c</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/ok5.c">ok5.c </a>
</th></tr>
<tr align="center">
<td><a class="title" href="http://www.gnu.org/manual/glibc-2.2.5/html_node/Heap-Consistency-Checking.html">MALLOC_CHECK_</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong7.out">*</a>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td></tr>
<tr align="center">
<td><a class="title" href="http://dmalloc.com/">dmalloc</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td></tr>
<tr align="center">
<td><a class="title" href="http://prj.softpixel.com/mcd/">memCheckDeluxe</a>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td></tr>
<tr align="center">
<td><a class="title" href="http://www.linkdata.se/sourcecode.html">memwatch</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/memwatch-response.txt">*</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td></tr>
<tr align="center">
<td><a class="title" href="http://duma.sourceforge.net/">DUMA</a>
</td><td><b><font color="darkgreen">OK</font></b>
<!-- segfaults on the bad write, but misses the bad read -->
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
<!-- segfaults on the first bug. That counts as finding it -->
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK<a href="http://www.cs.utexas.edu/%7Ejpmartin/duma-l2c.txt">*</a></font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td></tr>
<tr align="center">
<td><a class="title" href="http://devel-home.kde.org/%7Esewardj/">valgrind</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td></tr>
</tbody></table>
</p><p>
</p><h3>C++ tests</h3>
<table border="1">
<tbody><tr>
<th>Checker
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong1.cc">wrong1.cc</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong2.cc">wrong2.cc</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong3.cc">wrong3.cc</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong4.cc">wrong4.cc</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong5.cc">wrong5.cc</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong6.cc">wrong6.cc</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/leak1.cc">leak1.cc</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/leak2.cc">leak2.cc</a>
</th><th><a class="title" href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/ok5.cc">ok5.cc</a>
</th></tr>
<tr align="center">
<td><a class="title" href="http://www.gnu.org/manual/glibc-2.2.5/html_node/Heap-Consistency-Checking.html">MALLOC_CHECK_</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td></tr>
<tr align="center">
<td><a class="title" href="http://dmalloc.com/">dmalloc</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/dmalloc-wrong2.txt">*</a></b>
</td><td><b><font color="darkred">missed</font><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/dmalloc-wrong3.txt">*</a></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/dmalloc-ok5.txt">*</a></b>
</td></tr>
<tr align="center">
<td><a class="title" href="http://duma.sourceforge.net/">DUMA</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
<!-- caught the write to uninitialized memory, but not the read -->
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td></tr>
<tr align="center">
<td><a class="title" href="http://devel-home.kde.org/%7Esewardj/">valgrind</a>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK<a href="http://www.cs.utexas.edu/%7Ejpmartin/valgrind-w3cc.txt">*</a></font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkred">missed</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td><td><b><font color="darkgreen">OK</font></b>
</td></tr>
</tbody></table>
<p>
</p><h3>Conclusion</h3>
<p align="justify">
memWatch and memCheckDeluxe are both memory leak detectors, and they
passed all the memory leak tests. Memwatch wins this round because it
was able to detect the double-free in wrong1.c and the out-of-bounds
accesses in the dynamically allocated array of wrong7.c (not the
static array of wrong6 - but no one else did, either).
Both programs are designed to work with C and require a
recompilation.
</p>
<p align="justify">
MALLOC_CHECK_ is an interesting test: it is triggered simply by
setting the environment variable MALLOC_CHECK_ to 1, and the rest of
the magic is done by glibc (see the link in references, below). This
is the easiest check to set up and it requires no recompilation. It
detected the double free in wrong1 and the mismatched malloc/delete or
new/free pairs in wrong2.cc and wrong5.cc. It was able to see that
something was fishy in wrong7.c, but it reports a single error at the "free"
instead of when we are accessing the memory instead of two errors, for
each out-of-bounds access. MALLOC_CHECK_ cannot detect
memory leaks and did not detect the use of uninitialized memory in
wrong3.
</p>
<p align="justify">
dmalloc is more than a leak detector, but it didn't detect as
many bad cases as valgrind and requires a recompile. Also, its C++
support is (in the author's words) minimal. In particular, I have not
been able to get dmalloc to report line numbers with C++ (<a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/dmalloc-cpp.txt">log</a>), although that feature mostly
works with C code - in both leak1.c and leak2.c it pointed to
the <tt>return()</tt> instead of the line that allocated the unfreed
memory. Dmalloc also often reports unfreed memory, even for programs
that are correct. This may be because of errors in the c++ library,
but it makes the reports harder to read. In contrast, valgrind has a
way to hide leaks that it knows about so its reports are more
clear. See also the <a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/dmalloc-feedback.txt">author's comments</a>.
</p>
<p align="justify">
valgrind is clearly the winner of this little contest. valgrind
requires no recompilation of the program, so it's very easy to set
up. It identified almost all of the incorrect pointer uses and memory
leaks. The only test that it missed is wrong6, in which we break the
bounds of an array. No other checker spotted that one, though. Also,
valgrind has been improved since we ran this test, so it may perform
even better than what we show here.
</p>
<p align="justify">
DUMA is a very close second. The results I am posting here come from
Koneru Srikanth (kpsrikanth at gmail dot com) who generously sent them
to me. DUMA seems not to require a recompile, but the tests were run
on recompiled code. DUMA performs really well. It was also able to
detect out-of-bounds writes
(it is reported as failing wrong3.cc because it missed the
out-of-bounds read). If for some reason valgrind does not work for
you, then I recommend that you give DUMA a spin.
</p><h3>Reference</h3>
I tested:
<ul>
<li><a href="http://www.gnu.org/manual/glibc-2.2.5/html_node/Heap-Consistency-Checking.html">MALLOC_CHECK_</a>
for glibc (C and C++: requires no recompilation)
</li><li><a href="http://dmalloc.com/">dmalloc-5.2.2</a> (C, minimal C++ support; requires recompilation)
</li><li><a href="http://prj.softpixel.com/mcd/">memCheckDeluxe-1.2.2</a> (C,
some C++. Requires recompilation)
</li><li><a href="http://www.linkdata.se/sourcecode.html">memwatch-2.71</a> (C
only; requires recompilation)
</li><li><a href="http://devel-home.kde.org/%7Esewardj/">valgrind-1.9.6</a>
(C, C++ and more: requires no recompilation)
</li><li><a href="http://duma.sourceforge.net/">DUMA</a> version 2.4.26
(C and C++. Documentation says that no recompilation is needed, but
the tests were run on recompiled code) (as mentioned above, these tests
were contributed by Koneru Srikanth).
</li></ul>
I did not test:
<ul>
<li><a href="http://perens.com/FreeSoftware/">electric fence-2.1</a>
(did not compile on first attempt (<a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/efence-output.txt">log</a>))
</li><li><a href="http://check.sourceforge.net/">Checker-0.9.9.1</a> (did
not compile on first attempt (<a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/checker-output.txt">log</a>); author suggests I use
valgrind instead)
</li></ul>
Test programs:
<ul>
<li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong1.c">wrong1.c</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong3.c">wrong3.c</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong6.c">wrong6.c</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong7.c">wrong7.c</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/leak1.c">leak1.c</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/leak2.c">leak2.c</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/ok5.c">ok5.c </a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong1.cc">wrong1.cc</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong2.cc">wrong2.cc</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong3.cc">wrong3.cc</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong4.cc">wrong4.cc</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong5.cc">wrong5.cc</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/wrong6.cc">wrong6.cc</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/leak1.cc">leak1.cc</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/leak2.cc">leak2.cc</a>
</li><li><a href="http://www.cs.utexas.edu/%7Ejpmartin/memcheck/ok5.cc">ok5.cc</a>
</li></ul>
<h3>ToDo</h3>
The following memory checkers have been mentionned to me but I haven't
tried them yet:
<ul>
<li>mpatrol at http://www.cbmamiga.demon.co.uk/mpatrol/
</li></ul>
<h3>Change History</h3>
March 10, 2006: added DUMA, contributed by Koneru Srikanth
<br>
Oct 6, 2003: mention of mpatrol
<br>
Sept 29, 2003: added dmalloc
<br>
June 25, 2003: minor change in the text
<br>
June 24, 2003: corrected result for memwatch's wrong1.c, added wrong7.c
<br>
June 15, 2003: initial release
<p>
Please <a href="http://www.cs.utexas.edu/%7Ejpmartin/contact.html">contact</a> me if you have feedback or
would like to suggest another tool for the test.
</p><p></p><hr>
[<a accesskey="j" href="http://www.cs.utexas.edu/%7Ejpmartin/index.html"><b>J</b>P Martin</a>]
[<a accesskey="s" href="http://www.cs.utexas.edu/%7Ejpmartin/resources.html">re<b>s</b>ources</a>]
[<a accesskey="c" href="http://www.cs.utexas.edu/%7Ejpmartin/contact.html"><b>c</b>ontact information</a>]
<p>
</p><center>
<a href="http://www.anybrowser.org/campaign/"><img src="memCheckers-Dateien/viewed-any.gif" alt="Best viewed with *any* browser" border="0" height="30" width="85"></a>
</center>
</body></html>
|