
{"id":14248,"date":"2013-09-23T21:35:01","date_gmt":"2013-09-23T21:35:01","guid":{"rendered":"http:\/\/www.beautifulwork.org\/?p=14248"},"modified":"2013-09-23T21:35:01","modified_gmt":"2013-09-23T21:35:01","slug":"detecting-memory-leaks-still-reachable","status":"publish","type":"post","link":"https:\/\/www.trueangle.org\/index.php\/2013\/09\/23\/detecting-memory-leaks-still-reachable\/","title":{"rendered":"Using Valgrind  to detect Memory Leaks  (still reachable)"},"content":{"rendered":"<p><u>ABOUT Memory Leak<\/u><\/p>\n<pre>\nIn computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations[1] in such a way that memory which is no longer needed is not released. A memory leak may also happen when an object is stored in memory but cannot be accessed by the running code.[2] A memory leak has symptoms similar to a number of other problems and generally can only be diagnosed by a programmer with access to the program's source code.\n\nA space leak occurs when a computer program uses more memory than necessary. In contrast to memory leaks, where the leaked memory is never released, the memory consumed by a space leak is released, but later than expected. [3]\n\nBecause they can exhaust available system memory as an application runs, memory leaks are often the cause of or a contributing factor to software aging.\n<\/pre>\n<p><u>ABOUT Valgrind<\/u><\/p>\n<pre>\nValgrind \/\u02c8v\u00e6l\u0261r\u026and\/ is a programming tool for memory debugging, memory leak detection, and profiling.\n\nValgrind was originally designed to be a free memory debugging tool for Linux on x86, but has since evolved to become a generic framework for creating dynamic analysis tools such as checkers and profilers.\n\nThe name Valgrind is a reference to the main entrance of Valhalla from Norse Mythology. During development (before release) the project was named Heimdall; however, the name would have conflicted with a security package.\n<\/pre>\n<p><u>TYPICAL COMMANDLINE SESSION<\/u><br \/>\n[text light=&#8221;true&#8221;]<br \/>\n$valgrind -v &#8211;tool=memcheck &#8211;leak-check=full .\/ethstatus -i eth1<br \/>\n==19477== Memcheck, a memory error detector<br \/>\n==19477== Copyright (C) 2002-2012, and GNU GPL&#8217;d, by Julian Seward et al.<br \/>\n==19477== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info<br \/>\n==19477== Command: .\/ethstatus -i eth1<br \/>\n==19477==<br \/>\n&#8211;19477&#8211; Valgrind options:<br \/>\n&#8211;19477&#8211;    &#8211;suppressions=\/usr\/lib\/valgrind\/debian-libc6-dbg.supp<br \/>\n&#8211;19477&#8211;    -v<br \/>\n&#8211;19477&#8211;    &#8211;tool=memcheck<br \/>\n&#8211;19477&#8211;    &#8211;leak-check=full<br \/>\n&#8211;19477&#8211; Contents of \/proc\/version:<br \/>\n&#8211;19477&#8211;   Linux version 3.11.0 (root@debian) (gcc version 4.7.3 (Debian 4.7.3-4) ) #1 SMP Mon Sep 16 00:32:04 IST 2013<br \/>\n&#8211;19477&#8211; Arch and hwcaps: AMD64, amd64-sse3-cx16-lzcnt-avx<br \/>\n&#8211;19477&#8211; Page sizes: currently 4096, max supported 4096<br \/>\n&#8211;19477&#8211; Valgrind library directory: \/usr\/lib\/valgrind<br \/>\n&#8211;19477&#8211; Reading syms from \/home\/jeffrin\/Cloud\/debian-develop\/ethstatus-0.4.3\/ethstatus<br \/>\n&#8211;19477&#8211; Reading syms from \/lib\/x86_64-linux-gnu\/ld-2.17.so<br \/>\n&#8211;19477&#8211;   Considering \/lib\/x86_64-linux-gnu\/ld-2.17.so ..<br \/>\n&#8211;19477&#8211;   .. CRC mismatch (computed bf253f8a wanted e079394a)<br \/>\n&#8211;19477&#8211;   Considering \/usr\/lib\/debug\/lib\/x86_64-linux-gnu\/ld-2.17.so ..<br \/>\n&#8211;19477&#8211;   .. CRC is valid<br \/>\n&#8211;19477&#8211; Reading syms from \/usr\/lib\/valgrind\/memcheck-amd64-linux<br \/>\n&#8211;19477&#8211;   Considering \/usr\/lib\/valgrind\/memcheck-amd64-linux ..<br \/>\n&#8211;19477&#8211;   .. CRC mismatch (computed 3468463e wanted c047c437)<br \/>\n&#8211;19477&#8211;   Considering \/usr\/lib\/debug\/usr\/lib\/valgrind\/memcheck-amd64-linux ..<br \/>\n&#8211;19477&#8211;   .. CRC is valid<br \/>\n&#8211;19477&#8211;    object doesn&#8217;t have a dynamic symbol table<br \/>\n&#8211;19477&#8211; Scheduler: using generic scheduler lock implementation.<br \/>\n&#8211;19477&#8211; Reading suppressions file: \/usr\/lib\/valgrind\/debian-libc6-dbg.supp<br \/>\n&#8211;19477&#8211; Reading suppressions file: \/usr\/lib\/valgrind\/default.supp<br \/>\n==19477== embedded gdbserver: reading from \/tmp\/vgdb-pipe-from-vgdb-to-19477-by-jeffrin-on-???<br \/>\n==19477== embedded gdbserver: writing to   \/tmp\/vgdb-pipe-to-vgdb-from-19477-by-jeffrin-on-???<br \/>\n==19477== embedded gdbserver: shared mem   \/tmp\/vgdb-pipe-shared-mem-vgdb-19477-by-jeffrin-on-???<br \/>\n==19477==<br \/>\n==19477== TO CONTROL THIS PROCESS USING vgdb (which you probably<br \/>\n==19477== don&#8217;t want to do, unless you know exactly what you&#8217;re doing,<br \/>\n==19477== or are doing some strange experiment):<br \/>\n==19477==   \/usr\/lib\/valgrind\/..\/..\/bin\/vgdb &#8211;pid=19477 &#8230;command&#8230;<br \/>\n==19477==<br \/>\n==19477== TO DEBUG THIS PROCESS USING GDB: start GDB like this<br \/>\n==19477==   \/path\/to\/gdb .\/ethstatus<br \/>\n==19477== and then give GDB the following command<br \/>\n==19477==   target remote | \/usr\/lib\/valgrind\/..\/..\/bin\/vgdb &#8211;pid=19477<br \/>\n==19477== &#8211;pid is optional if only one valgrind process is running<br \/>\n==19477==<br \/>\n&#8211;19477&#8211; REDIR: 0x4017890 (strlen) redirected to 0x3806c661 (vgPlain_amd64_linux_REDIR_FOR_strlen)<br \/>\n&#8211;19477&#8211; Reading syms from \/usr\/lib\/valgrind\/vgpreload_core-amd64-linux.so<br \/>\n&#8211;19477&#8211;   Considering \/usr\/lib\/valgrind\/vgpreload_core-amd64-linux.so ..<br \/>\n&#8211;19477&#8211;   .. CRC mismatch (computed 3468909c wanted 2ffaf283)<br \/>\n&#8211;19477&#8211;   Considering \/usr\/lib\/debug\/usr\/lib\/valgrind\/vgpreload_core-amd64-linux.so ..<br \/>\n&#8211;19477&#8211;   .. CRC is valid<br \/>\n&#8211;19477&#8211; Reading syms from \/usr\/lib\/valgrind\/vgpreload_memcheck-amd64-linux.so<br \/>\n&#8211;19477&#8211;   Considering \/usr\/lib\/valgrind\/vgpreload_memcheck-amd64-linux.so ..<br \/>\n&#8211;19477&#8211;   .. CRC mismatch (computed c6ae4a33 wanted 21397e4b)<br \/>\n&#8211;19477&#8211;   Considering \/usr\/lib\/debug\/usr\/lib\/valgrind\/vgpreload_memcheck-amd64-linux.so ..<br \/>\n&#8211;19477&#8211;   .. CRC is valid<br \/>\n&#8211;19477&#8211; REDIR: 0x4017700 (index) redirected to 0x4c2c4b0 (index)<br \/>\n&#8211;19477&#8211; REDIR: 0x4017780 (strcmp) redirected to 0x4c2d4c0 (strcmp)<br \/>\n&#8211;19477&#8211; Reading syms from \/usr\/lib\/debug\/libncurses.so.5.9<br \/>\n&#8211;19477&#8211; Reading syms from \/usr\/lib\/debug\/libtinfo.so.5.9<br \/>\n&#8211;19477&#8211; Reading syms from \/lib\/x86_64-linux-gnu\/libc-2.17.so<br \/>\n&#8211;19477&#8211;   Considering \/lib\/x86_64-linux-gnu\/libc-2.17.so ..<br \/>\n&#8211;19477&#8211;   .. CRC mismatch (computed b0b3185d wanted a268c1003)<br \/>\n&#8211;19477&#8211;   Considering \/usr\/lib\/debug\/lib\/x86_64-linux-gnu\/libc-2.17.so ..<br \/>\n&#8211;19477&#8211;   .. CRC is valid<br \/>\n&#8211;19477&#8211; Reading syms from \/lib\/x86_64-linux-gnu\/libdl-2.17.so<br \/>\n&#8211;19477&#8211;   Considering \/lib\/x86_64-linux-gnu\/libdl-2.17.so ..<br \/>\n&#8211;19477&#8211;   .. CRC mismatch (computed 2a2457cb wanted a5918d1a)<br \/>\n&#8211;19477&#8211;   Considering \/usr\/lib\/debug\/lib\/x86_64-linux-gnu\/libdl-2.17.so ..<br \/>\n&#8211;19477&#8211;   .. CRC is valid<br \/>\n&#8211;19477&#8211; REDIR: 0x5317e40 (strcasecmp) redirected to 0x4a24710 (_vgnU_ifunc_wrapper)<br \/>\n&#8211;19477&#8211; REDIR: 0x5314200 (strnlen) redirected to 0x4a24710 (_vgnU_ifunc_wrapper)<br \/>\n&#8211;19477&#8211; REDIR: 0x531a110 (strncasecmp) redirected to 0x4a24710 (_vgnU_ifunc_wrapper)<br \/>\n&#8211;19477&#8211; REDIR: 0x5316c50 (memset) redirected to 0x4a24710 (_vgnU_ifunc_wrapper)<br \/>\n&#8211;19477&#8211; REDIR: 0x5316c00 (memcpy@GLIBC_2.2.5) redirected to 0x4a24710 (_vgnU_ifunc_wrapper)<br \/>\n&#8211;19477&#8211; REDIR: 0x5315bf0 (__GI_strrchr) redirected to 0x4c2c2d0 (__GI_strrchr)<br \/>\n&#8211;19477&#8211; REDIR: 0xffffffffff600400 (???) redirected to 0x3806c64d (vgPlain_amd64_linux_REDIR_FOR_vtime)<br \/>\n&#8211;19477&#8211; REDIR: 0x5314120 (__GI_strlen) redirected to 0x4c2c830 (__GI_strlen)<br \/>\n&#8211;19477&#8211; REDIR: 0x530e4f0 (free) redirected to 0x4c2aa70 (free)<br \/>\n&#8211;19477&#8211; REDIR: 0x530e0d0 (malloc) redirected to 0x4c2bd80 (malloc)<br \/>\n&#8211;19477&#8211; REDIR: 0x5313ab0 (__GI_strcpy) redirected to 0x4c2c920 (__GI_strcpy)<br \/>\n&#8211;19477&#8211; REDIR: 0x5312620 (__GI_strcmp) redirected to 0x4c2d470 (__GI_strcmp)<br \/>\n&#8211;19477&#8211; REDIR: 0x531dc10 (__GI___rawmemchr) redirected to 0x4c2ee90 (__GI___rawmemchr)<br \/>\n&#8211;19477&#8211; REDIR: 0x531de20 (strchrnul) redirected to 0x4c2ee40 (strchrnul)<br \/>\n&#8211;19477&#8211; REDIR: 0x5314230 (__GI_strnlen) redirected to 0x4c2c7e0 (__GI_strnlen)<br \/>\n&#8211;19477&#8211; REDIR: 0x5312560 (__GI_strchr) redirected to 0x4c2c3b0 (__GI_strchr)<br \/>\nRunning EthStatus v0.4a&#8230;&#8211;19477&#8211; REDIR: 0x5314320 (__GI_strncmp) redirected to 0x4c2cd00 (__GI_strncmp)<br \/>\n&#8211;19477&#8211; REDIR: 0x53140d0 (strlen) redirected to 0x4a24710 (_vgnU_ifunc_wrapper)<br \/>\n&#8211;19477&#8211; REDIR: 0x530ea30 (calloc) redirected to 0x4c29ba0 (calloc)<br \/>\n&#8211;19477&#8211; REDIR: 0x5315bb0 (rindex) redirected to 0x4a24710 (_vgnU_ifunc_wrapper)<br \/>\n&#8211;19477&#8211; REDIR: 0x5312520 (index) redirected to 0x4a24710 (_vgnU_ifunc_wrapper)<br \/>\n&#8211;19477&#8211; REDIR: 0x5313a70 (strcpy) redirected to 0x4a24710 (_vgnU_ifunc_wrapper)<br \/>\n&#8211;19477&#8211; REDIR: 0x53125e0 (strcmp) redirected to 0x4a24710 (_vgnU_ifunc_wrapper)<br \/>\n&#8211;19477&#8211; REDIR: 0x531c7f0 (memcpy@@GLIBC_2.14) redirected to 0x4a24710 (_vgnU_ifunc_wrapper)<br \/>\n&#8211;19477&#8211; REDIR: 0x531c840 (__GI_memcpy) redirected to 0x4c2d7f0 (memcpy@@GLIBC_2.14)<br \/>\n&#8211;19477&#8211; REDIR: 0x530e580 (realloc) redirected to 0x4c2bf80 (realloc)<br \/>\n&#8211;19477&#8211; REDIR: 0x5315b70 (strncpy) redirected to 0x4a24710 (_vgnU_ifunc_wrapper)<br \/>\n&#8211;19477&#8211; REDIR: 0x53214b0 (__GI_strncpy) redirected to 0x4c2cb40 (__GI_strncpy)<br \/>\n&#8211;19477&#8211; REDIR: 0x532b4f0 (strstr) redirected to 0x4a24710 (_vgnU_ifunc_wrapper)<br \/>\n&#8211;19477&#8211; REDIR: 0x532b060 (__GI_strstr) redirected to 0x4c2f240 (strstr)<\/p>\n<p>EthStatus v0.4a &#8211; Gabriel Montenegro \/ Christoph Haas<\/p>\n<p>==19477==<br \/>\n==19477== HEAP SUMMARY:<br \/>\n==19477==     in use at exit: 85,525 bytes in 122 blocks<br \/>\n==19477==   total heap usage: 22,300 allocs, 22,178 frees, 6,549,861 bytes allocated<br \/>\n==19477==<br \/>\n==19477== Searching for pointers to 122 not-freed blocks<br \/>\n==19477== Checked 227,344 bytes<br \/>\n==19477==<br \/>\n==19477== LEAK SUMMARY:<br \/>\n==19477==    definitely lost: 0 bytes in 0 blocks<br \/>\n==19477==    indirectly lost: 0 bytes in 0 blocks<br \/>\n==19477==      possibly lost: 0 bytes in 0 blocks<br \/>\n==19477==    still reachable: 85,525 bytes in 122 blocks<br \/>\n==19477==         suppressed: 0 bytes in 0 blocks<br \/>\n==19477== Reachable blocks (those to which a pointer was found) are not shown.<br \/>\n==19477== To see them, rerun with: &#8211;leak-check=full &#8211;show-reachable=yes<br \/>\n==19477==<br \/>\n==19477== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)<br \/>\n&#8211;19477&#8211;<br \/>\n&#8211;19477&#8211; used_suppression:      2 dl-hack3-cond-1<br \/>\n==19477==<br \/>\n==19477== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)<br \/>\n$<\/p>\n<p>[\/text]<br \/>\nLINKS<br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Valgrind\">https:\/\/en.wikipedia.org\/wiki\/Valgrind<\/a><br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Memory_leak\">https:\/\/en.wikipedia.org\/wiki\/Memory_leak<\/a><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/26137356\/how-to-check-actual-memory-leaks-during-runtime-using-valgrind\">https:\/\/stackoverflow.com\/questions\/26137356\/how-to-check-actual-memory-leaks-during-runtime-using-valgrind<\/a><br \/>\n<a href=\"https:\/\/www.ibm.com\/developerworks\/library\/l-memory-leaks\/index.html\">https:\/\/www.ibm.com\/developerworks\/library\/l-memory-leaks\/index.html<\/a><br \/>\n<a href=\"https:\/\/www.ibm.com\/developerworks\/systems\/library\/es-debug\/index.html\">https:\/\/www.ibm.com\/developerworks\/systems\/library\/es-debug\/index.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>ABOUT Memory Leak In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations[1] in such a way that memory which is no longer needed is not released. A memory leak may also happen when an object is stored in memory but cannot be &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.trueangle.org\/index.php\/2013\/09\/23\/detecting-memory-leaks-still-reachable\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Using Valgrind  to detect Memory Leaks  (still reachable)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[83],"tags":[1109,1639],"_links":{"self":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/14248"}],"collection":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/comments?post=14248"}],"version-history":[{"count":0,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/14248\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/media?parent=14248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/categories?post=14248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/tags?post=14248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}