<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[张宴的博客]]></title> 
<link>http://zyan.cc/index.php</link> 
<description><![CDATA[Web系统架构与底层研发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[张宴的博客]]></copyright>
<item>
<link>http://zyan.cc/post/419/</link>
<title><![CDATA[Linux C/C++ 内存泄漏检测工具：Valgrind]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[其他Unix技术]]></category>
<pubDate>Fri, 31 Jul 2009 13:01:30 +0000</pubDate> 
<guid>http://zyan.cc/post/419/</guid> 
<description>
<![CDATA[ 
	　　Valgrind 是一款 Linux下（支持 x86、x86_64和ppc32）程序的内存调试工具，它可以对编译后的二进制程序进行内存使用监测（C语言中的malloc和free，以及C++中的new和delete），找出内存泄漏问题。<br/><br/>　　Valgrind 中包含的 Memcheck 工具可以检查以下的程序错误：<br/><br/>　　使用未初始化的内存 (Use of uninitialised memory)<br/>　　使用已经释放了的内存 (Reading/writing memory after it has been free’d)<br/>　　使用超过malloc分配的内存空间(Reading/writing off the end of malloc’d blocks)<br/>　　对堆栈的非法访问 (Reading/writing inappropriate areas on the stack)<br/>　　申请的空间是否有释放 (Memory leaks – where pointers to malloc’d blocks are lost forever)<br/>　　malloc/free/new/delete申请和释放内存的匹配(Mismatched use of malloc/new/new [] vs free/delete/delete [])<br/>　　src和dst的重叠(Overlapping src and dst pointers in memcpy() and related functions)<br/>　　重复free<br/><br/>　　1、编译安装 Valgrind：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">wget <a href="http://valgrind.org/downloads/valgrind-3.4.1.tar.bz2" target="_blank">http://valgrind.org/downloads/valgrind-3.4.1.tar.bz2</a><br/>tar xvf valgrind-3.4.1.tar.bz2<br/>cd valgrind-3.4.1/<br/>./configure --prefix=/usr/local/webserver/valgrind<br/>make<br/>make install</div><br/><br/>　　2、使用示例：对“ls”程序进程检查，返回结果中的“definitely lost: 0 bytes in 0 blocks.”表示没有内存泄漏。<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">[root@xoyo42 /]# <font color="green">/usr/local/webserver/valgrind/bin/valgrind --tool=memcheck --leak-check=full ls /</font><br/>==1157== Memcheck, a memory error detector.<br/>==1157== Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward et al.<br/>==1157== Using LibVEX rev 1884, a library for dynamic binary translation.<br/>==1157== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.<br/>==1157== Using valgrind-3.4.1, a dynamic binary instrumentation framework.<br/>==1157== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.<br/>==1157== For more details, rerun with: -v<br/>==1157== <br/>bin&nbsp;&nbsp; data0&nbsp;&nbsp;dev&nbsp;&nbsp;home&nbsp;&nbsp;lib64&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; media&nbsp;&nbsp;mnt&nbsp;&nbsp;opt&nbsp;&nbsp; root&nbsp;&nbsp;selinux&nbsp;&nbsp;sys&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tcsql.db.idx.pkey.dec&nbsp;&nbsp;ttserver.pid&nbsp;&nbsp;var<br/>boot&nbsp;&nbsp;data1&nbsp;&nbsp;etc&nbsp;&nbsp;lib&nbsp;&nbsp; lost+found&nbsp;&nbsp;misc&nbsp;&nbsp; net&nbsp;&nbsp;proc&nbsp;&nbsp;sbin&nbsp;&nbsp;srv&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tcsql.db&nbsp;&nbsp;tmp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;usr<br/>==1157== <br/>==1157== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 5 from 1)<br/>==1157== malloc/free: in use at exit: 28,471 bytes in 36 blocks.<br/>==1157== malloc/free: 166 allocs, 130 frees, 51,377 bytes allocated.<br/>==1157== For counts of detected errors, rerun with: -v<br/>==1157== searching for pointers to 36 not-freed blocks.<br/>==1157== checked 174,640 bytes.<br/>==1157== <br/>==1157== LEAK SUMMARY:<br/>==1157==&nbsp;&nbsp;&nbsp;&nbsp;<font color="red">definitely lost: 0 bytes in 0 blocks.</font><br/>==1157==&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;possibly lost: 0 bytes in 0 blocks.<br/>==1157==&nbsp;&nbsp;&nbsp;&nbsp;still reachable: 28,471 bytes in 36 blocks.<br/>==1157==&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; suppressed: 0 bytes in 0 blocks.<br/>==1157== Reachable blocks (those to which a pointer was found) are not shown.<br/>==1157== To see them, rerun with: --leak-check=full --show-reachable=yes</div><br/><br/>　　3、使用示例：对一个使用libevent库编写的“httptest”程序进程检查，返回结果中的“definitely lost: 255 bytes in 5 blocks.”表示发生内存泄漏。<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">[root@xoyo42 tcsql-0.1]# <font color="green">/usr/local/webserver/valgrind/bin/valgrind --tool=memcheck --leak-check=full ./httptest</font><br/>==1274== Memcheck, a memory error detector.<br/>==1274== Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward et al.<br/>==1274== Using LibVEX rev 1884, a library for dynamic binary translation.<br/>==1274== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.<br/>==1274== Using valgrind-3.4.1, a dynamic binary instrumentation framework.<br/>==1274== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.<br/>==1274== For more details, rerun with: -v<br/>==1274== <br/>==1274== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 1005 from 2)<br/>==1274== malloc/free: in use at exit: 402,291 bytes in 74 blocks.<br/>==1274== malloc/free: 15,939 allocs, 15,865 frees, 6,281,523 bytes allocated.<br/>==1274== For counts of detected errors, rerun with: -v<br/>==1274== searching for pointers to 74 not-freed blocks.<br/>==1274== checked 682,468,160 bytes.<br/>==1274== <br/>==1274== 255 bytes in 5 blocks are definitely lost in loss record 17 of 32<br/>==1274==&nbsp;&nbsp;&nbsp;&nbsp;at 0x4A05FBB: malloc (vg_replace_malloc.c:207)<br/>==1274==&nbsp;&nbsp;&nbsp;&nbsp;by 0x3C1D809BC6: <font color="red">evhttp_decode_uri (http.c:2105)</font><br/>==1274==&nbsp;&nbsp;&nbsp;&nbsp;by 0x401C75: tcsql_handler (in /data0/tcsql/cankao/tcsql-0.1/tcsql)<br/>==1274==&nbsp;&nbsp;&nbsp;&nbsp;by 0x3C1D80C88F: evhttp_get_body (http.c:1582)<br/>==1274==&nbsp;&nbsp;&nbsp;&nbsp;by 0x3C1D8065F7: event_base_loop (event.c:392)<br/>==1274==&nbsp;&nbsp;&nbsp;&nbsp;by 0x403E2F: main (in /data0/tcsql/cankao/tcsql-0.1/tcsql)<br/>==1274== <br/>==1274== LEAK SUMMARY:<br/>==1274==&nbsp;&nbsp;&nbsp;&nbsp;<font color="red">definitely lost: 255 bytes in 5 blocks.</font><br/>==1274==&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;possibly lost: 0 bytes in 0 blocks.<br/>==1274==&nbsp;&nbsp;&nbsp;&nbsp;still reachable: 402,036 bytes in 69 blocks.<br/>==1274==&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; suppressed: 0 bytes in 0 blocks.<br/>==1274== Reachable blocks (those to which a pointer was found) are not shown.<br/>==1274== To see them, rerun with: --leak-check=full --show-reachable=yes</div><br/><br/>　　检查httptest程序，发现有一处“char *decode_uri = evhttp_decode_uri(evhttp_request_uri(req));”中的“decode_uri”没有被free，再程序处理完成后加上“free(decode_uri);”后，再使用Valgrind检查，结果已经是“definitely lost: 0 bytes in 0 blocks.”。<br/><br/><br/>Tags - <a href="http://zyan.cc/tags/valgrind/" rel="tag">valgrind</a> , <a href="http://zyan.cc/tags/c/" rel="tag">c</a> , <a href="http://zyan.cc/tags/c%252B%252B/" rel="tag">c++</a> , <a href="http://zyan.cc/tags/c%252Fc%252B%252B/" rel="tag">c/c++</a> , <a href="http://zyan.cc/tags/%25E5%2586%2585%25E5%25AD%2598%25E8%25B0%2583%25E8%25AF%2595/" rel="tag">内存调试</a> , <a href="http://zyan.cc/tags/%25E5%2586%2585%25E5%25AD%2598%25E6%25B3%2584%25E6%25BC%258F/" rel="tag">内存泄漏</a> , <a href="http://zyan.cc/tags/%25E5%2586%2585%25E5%25AD%2598%25E6%25B3%2584%25E6%25BC%258F%25E6%25A3%2580%25E6%25B5%258B/" rel="tag">内存泄漏检测</a>
]]>
</description>
</item><item>
<link>http://zyan.cc/post/419/#blogcomment3779</link>
<title><![CDATA[[评论] Linux C/C++ 内存泄漏检测工具：Valgrind]]></title> 
<author>美国VPS推荐 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 01 Aug 2009 04:57:28 +0000</pubDate> 
<guid>http://zyan.cc/post/419/#blogcomment3779</guid> 
<description>
<![CDATA[ 
	路过学习。。。<br/><br/><br/><a href="http://www.vpser.net/usa-vps/" target="_blank">美国VPS推荐</a>
]]>
</description>
</item><item>
<link>http://zyan.cc/post/419/#blogcomment3780</link>
<title><![CDATA[[评论] Linux C/C++ 内存泄漏检测工具：Valgrind]]></title> 
<author>ritto &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 01 Aug 2009 05:55:27 +0000</pubDate> 
<guid>http://zyan.cc/post/419/#blogcomment3780</guid> 
<description>
<![CDATA[ 
	学习。。。。
]]>
</description>
</item><item>
<link>http://zyan.cc/post/419/#blogcomment3786</link>
<title><![CDATA[[评论] Linux C/C++ 内存泄漏检测工具：Valgrind]]></title> 
<author>偶行偶酷 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sun, 02 Aug 2009 01:39:59 +0000</pubDate> 
<guid>http://zyan.cc/post/419/#blogcomment3786</guid> 
<description>
<![CDATA[ 
	如果要查 一些java 程序<br/><br/>或者jsp&nbsp;&nbsp;， php&nbsp;&nbsp;等web 程序 如何查？<br/><br/>是 valgrind --tool=memcheck --leak-check=full /usr/bin/local/bin/php /web/www/index.php<br/><br/>这样吗？
]]>
</description>
</item><item>
<link>http://zyan.cc/post/419/#blogcomment3795</link>
<title><![CDATA[[评论] Linux C/C++ 内存泄漏检测工具：Valgrind]]></title> 
<author>ZNZ &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 03 Aug 2009 04:35:28 +0000</pubDate> 
<guid>http://zyan.cc/post/419/#blogcomment3795</guid> 
<description>
<![CDATA[ 
	很好 学习了
]]>
</description>
</item><item>
<link>http://zyan.cc/post/419/#blogcomment3796</link>
<title><![CDATA[[评论] Linux C/C++ 内存泄漏检测工具：Valgrind]]></title> 
<author>卢松松 &lt;reed@vip.qq.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 03 Aug 2009 05:14:08 +0000</pubDate> 
<guid>http://zyan.cc/post/419/#blogcomment3796</guid> 
<description>
<![CDATA[ 
	不错 我也受教了
]]>
</description>
</item><item>
<link>http://zyan.cc/post/419/#blogcomment3805</link>
<title><![CDATA[[评论] Linux C/C++ 内存泄漏检测工具：Valgrind]]></title> 
<author>vps观察者 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 04 Aug 2009 09:34:20 +0000</pubDate> 
<guid>http://zyan.cc/post/419/#blogcomment3805</guid> 
<description>
<![CDATA[ 
	目前正在学习linux，受教了。
]]>
</description>
</item><item>
<link>http://zyan.cc/post/419/#blogcomment3807</link>
<title><![CDATA[[评论] Linux C/C++ 内存泄漏检测工具：Valgrind]]></title> 
<author>tsseo &lt;tsseo@126.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Tue, 04 Aug 2009 09:59:15 +0000</pubDate> 
<guid>http://zyan.cc/post/419/#blogcomment3807</guid> 
<description>
<![CDATA[ 
	很实用的工具！呵呵，学习了！-<a href="http://www.yinfengming.org" target="_blank">SEO</a>ER
]]>
</description>
</item><item>
<link>http://zyan.cc/post/419/#blogcomment3823</link>
<title><![CDATA[[评论] Linux C/C++ 内存泄漏检测工具：Valgrind]]></title> 
<author>eyre &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 07 Aug 2009 02:56:53 +0000</pubDate> 
<guid>http://zyan.cc/post/419/#blogcomment3823</guid> 
<description>
<![CDATA[ 
	请问用的Linux内核版本号是多少？我也正研究这个工具，在2.6.18的系统下make部分老报什么&quot;符号链接……不允许的操作&quot;，我不知道是不是还有什么没安装的
]]>
</description>
</item><item>
<link>http://zyan.cc/post/419/#blogcomment5467</link>
<title><![CDATA[[评论] Linux C/C++ 内存泄漏检测工具：Valgrind]]></title> 
<author>tawl &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Apr 2010 08:33:01 +0000</pubDate> 
<guid>http://zyan.cc/post/419/#blogcomment5467</guid> 
<description>
<![CDATA[ 
	这个对于只能处理一些内存错误吧？
]]>
</description>
</item><item>
<link>http://zyan.cc/post/419/#blogcomment6280</link>
<title><![CDATA[[评论] Linux C/C++ 内存泄漏检测工具：Valgrind]]></title> 
<author>侬本多情 &lt;shine@bld.cc&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 03 Jul 2010 02:16:42 +0000</pubDate> 
<guid>http://zyan.cc/post/419/#blogcomment6280</guid> 
<description>
<![CDATA[ 
	内存问题总是很头疼..
]]>
</description>
</item><item>
<link>http://zyan.cc/post/419/#blogcomment6381</link>
<title><![CDATA[[评论] Linux C/C++ 内存泄漏检测工具：Valgrind]]></title> 
<author>小yú &lt;newpublic01@gmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 19 Jul 2010 16:07:09 +0000</pubDate> 
<guid>http://zyan.cc/post/419/#blogcomment6381</guid> 
<description>
<![CDATA[ 
	动态跟踪有个不太方便的地儿：比如要跟踪一个服务，就有些不爽了，所以还需要静态检测先，呵呵至少俺个人认为如此呵呵
]]>
</description>
</item><item>
<link>http://zyan.cc/post/419/#blogcomment7004</link>
<title><![CDATA[[评论] Linux C/C++ 内存泄漏检测工具：Valgrind]]></title> 
<author>千书汇 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 18 Oct 2010 07:45:37 +0000</pubDate> 
<guid>http://zyan.cc/post/419/#blogcomment7004</guid> 
<description>
<![CDATA[ 
	不错学习了
]]>
</description>
</item><item>
<link>http://zyan.cc/post/419/#blogcomment14259</link>
<title><![CDATA[[评论] Linux C/C++ 内存泄漏检测工具：Valgrind]]></title> 
<author>louis vuitton uk &lt;fsf@fdg.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Wed, 23 Nov 2011 01:13:10 +0000</pubDate> 
<guid>http://zyan.cc/post/419/#blogcomment14259</guid> 
<description>
<![CDATA[ 
	This <a href="http://www.louisvuittonoutlets.org.uk" target="_blank">louis vuitton uk</a> for sale belongs to the sounding just what are termed as Louis Vuitton vintage best sellers, many other products and services for the reason that range appearing companies.You will easily notice the unfold zippers of this <a href="http://www.coachoutletstoreonlinefree.com" target="_blank">coach outlet store online</a>. That is the decoration. There are some inside pockets for you as well. They are easy to match your clothes and to carry.Let us inspire your inner beauty with fine <a href="http://www.christian-louboutinsale.org.uk" target="_blank">christian louboutin sale</a>. Purse the elegance in bridal wedding. Enjoy the fashion.
]]>
</description>
</item><item>
<link>http://zyan.cc/post/419/#blogcomment17478</link>
<title><![CDATA[[评论] Linux C/C++ 内存泄漏检测工具：Valgrind]]></title> 
<author>meimei &lt;xiangxiangxiang123@yahoo.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 16 Apr 2012 00:53:00 +0000</pubDate> 
<guid>http://zyan.cc/post/419/#blogcomment17478</guid> 
<description>
<![CDATA[ 
	<a href="http://www.christianlouboutinukuk.org" target="_blank">christian louboutin</a><br/><a href="http://www.tiffanyuksuk.org" target="_blank">tiffanys</a><br/><a href="http://www.gucciukbeltuk.org" target="_blank">gucci uk</a><br/><a href="http://www.frsaclouisvuittonsac.com" target="_blank">louis vuitton sac</a>
]]>
</description>
</item><item>
<link>http://zyan.cc/post/419/#blogcomment17495</link>
<title><![CDATA[[评论] Linux C/C++ 内存泄漏检测工具：Valgrind]]></title> 
<author>meimei &lt;xiangxiangxiang123@yahoo.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Mon, 16 Apr 2012 00:59:03 +0000</pubDate> 
<guid>http://zyan.cc/post/419/#blogcomment17495</guid> 
<description>
<![CDATA[ 
	<a href="http://www.chanelukoutlets.org.uk" target="_blank">chanel uk</a><br/><a href="http://www.burberryukoutletuk.org" target="_blank">burberry uk</a><br/><a href="http://www.poloralphlaurenuks.org" target="_blank">ralph lauren uk</a>
]]>
</description>
</item>
</channel>
</rss>