memCheckers.html 16 KB

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