{"id":14,"date":"2017-04-19T17:25:30","date_gmt":"2017-04-19T09:25:30","guid":{"rendered":"http:\/\/www.myway5.com\/?p=14"},"modified":"2018-06-26T12:35:33","modified_gmt":"2018-06-26T04:35:33","slug":"linux-c-or-c-plus-plus-memory-leak-analysis","status":"publish","type":"post","link":"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/","title":{"rendered":"linux\u4e0bc\/c++\u7684\u5185\u5b58\u6cc4\u6f0f\u5206\u6790"},"content":{"rendered":"<p>\u4f7f\u7528valgrind\u8fdb\u884c\u5185\u5b58\u5206\u6790<\/p>\n<h2>\u7b80\u4ecb<\/h2>\n<p>\u5b98\u7f51\u5730\u5740:http:\/\/valgrind.org<br \/>\n\u4e3b\u8981\u63d0\u4f9b\u4ee5\u4e0b\u5de5\u5177\uff1a<\/p>\n<blockquote><p>\n  <strong>Memcheck<\/strong> \u662f\u4e00\u4e2a\u5185\u5b58\u9519\u8bef\u7684\u68c0\u6d4b\u5de5\u5177\uff0c\u5e2e\u52a9\u4f60\u7684\u7a0b\u5e8f\uff0c\u5c24\u5176\u662fc\/c++\u7a0b\u5e8f\u51fa\u73b0\u66f4\u5c11\u5185\u5b58\u7684\u95ee\u9898\u3002<br \/>\n  <strong>Cachegrind<\/strong> \u662f\u4e00\u4e2a\u7f13\u5b58\u548c\u5206\u652f\u9884\u6d4b\u63a2\u67e5\u5de5\u5177\uff0c\u5e2e\u52a9\u4f60\u7684\u7a0b\u5e8f\u8fd0\u884c\u7684\u66f4\u5feb\u3002<br \/>\n  <strong>Callgrind<\/strong> \u4e5f\u662f\u4e00\u4e2a\u548c\u7f13\u5b58\u76f8\u5173\u7684\u8c03\u7528\u56fe\u5de5\u5177\uff0c\u548cCachegrind\u6709\u4e00\u90e8\u5206\u91cd\u53e0\uff0c\u4f46\u4e5f\u751f\u6210\u4e00\u4e9bCachegrind\u4e0d\u63d0\u4f9b\u7684\u4fe1\u606f\u3002<br \/>\n  <strong>Helgrind<\/strong> \u662f\u4e00\u4e2a\u7ebf\u7a0b\u9519\u8bef\u7684\u68c0\u6d4b\u5de5\u5177\uff0c\u5728\u591a\u7ebf\u7a0b\u573a\u666f\u4e0b\u80fd\u6d3e\u4e0a\u7528\u573a\u3002<br \/>\n  <strong>DRD<\/strong> \u4e5f\u662f\u4e00\u4e2a\u7ebf\u7a0b\u9519\u8bef\u7684\u68c0\u6d4b\u5de5\u5177\uff0c\u4e0eHelgrind\u529f\u80fd\u4e00\u6837\uff0c\u4f46\u662f\u4f7f\u7528\u4e86\u4e0d\u540c\u7684\u5206\u6790\u6280\u672f\uff0c\u53ef\u80fd\u4f1a\u53d1\u73b0\u4e0d\u540c\u7684\u95ee\u9898\u3002<br \/>\n  <strong>Massif<\/strong> \u662f\u4e00\u4e2a\u5806\u5206\u6790\u5de5\u5177\uff0c\u5e2e\u52a9\u7a0b\u5e8f\u4f7f\u7528\u66f4\u5c11\u7684\u5185\u5b58\u3002<br \/>\n  <strong>DHAT<\/strong> \u662f\u4e0d\u540c\u4e0eMassif\u7684\u5806\u5206\u6790\u5de5\u5177\uff0c\u5e2e\u52a9\u4f60\u7406\u89e3\u5757\u7684\u751f\u547d\u5468\u671f, \u5757\u7684\u5229\u7528\u7387, \u4ee5\u53calayout\u7684\u4f4e\u6548\u3002<br \/>\n  <strong>SGcheck<\/strong> \u662f\u4e00\u4e2a\u5b9e\u9a8c\u6027\u7684\u5de5\u5177\uff0c\u5e2e\u52a9\u68c0\u6d4b\u6808\u7684\u8d85\u652f\u548c\u5168\u5c40\u6570\u7ec4\u3002\u662fMemcheck\u7684\u529f\u80fd\u65b9\u9762\u7684\u8865\u5145\uff1a\u53ef\u4ee5\u68c0\u6d4b\u51faMemcheck\u65e0\u6cd5\u53d1\u73b0\u7684\u95ee\u9898\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002<br \/>\n  <strong>BBV<\/strong> \u662f\u4e00\u4e2a\u5b9e\u9a8cSimPoint\u57fa\u672c\u5757\u5411\u91cf\u751f\u6210\u5668\u3002\u5bf9\u4e8e\u8fdb\u884c\u8ba1\u7b97\u673a\u4f53\u7cfb\u7ed3\u6784\u7814\u7a76\u548c\u5f00\u53d1\u7684\u4eba\u6765\u8bf4\uff0c\u8fd9\u662f\u6709\u7528\u7684\u3002\n<\/p><\/blockquote>\n<p>\u8fd9\u91cc\u8bb0\u5f55\u7684\u53ea\u662fMemcheck\u7684\u4f7f\u7528\uff0c\u5176\u4ed6\u7684\u4f7f\u7528\u53ef\u4ee5\u53c2\u8003\u4e0a\u8ff0\u7684\u5b98\u7f51\u7684\u7f51\u5740\u3002<\/p>\n<h2>ubuntu\u4e0b\u7684\u5b89\u88c5<\/h2>\n<blockquote><p>\n  sudo apt-get install valgrind\n<\/p><\/blockquote>\n<h2>\u4f7f\u7528\u65b9\u6cd5<\/h2>\n<blockquote><p>\n  valgrind [valgrind-options] your-prog [your-prog-options]\n<\/p><\/blockquote>\n<p>\u4f8b\u5982,\u5bf9ls -l\u8fdb\u884c\u5206\u6790:<\/p>\n<blockquote><p>\n  valgrind &#8211;tool=memcheck ls -l\n<\/p><\/blockquote>\n<p>valgrind\u7684\u9ed8\u8ba4\u5de5\u5177\u5c31\u662fmemcheck\uff0c\u6240\u4ee5\u4f7f\u7528memcheck\u5de5\u5177\u65f6\u53ef\u4ee5\u7701\u7565&#8211;tool\u53c2\u6570<\/p>\n<h2>\u6ce8\u610f\u4e8b\u9879:<\/h2>\n<p>1\u3001valgrind\u5de5\u5177\u4f1a\u51cf\u6162\u7a0b\u5e8f\u7684\u8fd0\u884c\u901f\u5ea6<br \/>\n2\u3001\u7a0b\u5e8f\u7f16\u8bd1\u65f6\u9700\u8981\u5f00\u542f-g\uff0c\u5e2e\u52a9valgrind\u53ef\u4ee5\u66f4\u7cbe\u51c6\u7684\u5b9a\u4f4d\u5230\u9519\u8bef<br \/>\n3\u3001\u7a0b\u5e8f\u7f16\u8bd1\u65f6\u6700\u597d\u5173\u95ed\u4f18\u5316\uff0c\u5426\u5219\u53ef\u80fd\u4ea7\u751f\u4e0d\u6b63\u786e\u7684\u672a\u521d\u59cb\u5316\u9519\u8bef\u4fe1\u606f\uff0c\u4ee5\u53ca\u9057\u6f0f\u672a\u521d\u59cb\u5316\u9519\u8bef\u3002<br \/>\n4\u3001\u7a0b\u5e8f\u7f16\u8bd1\u65f6\u6700\u597d\u4f7f\u7528-Wall\uff0c\u5e2e\u52a9valgrind\u5728\u9ad8\u4f18\u5316\u7b49\u7ea7\u7684\u7a0b\u5e8f\u4e2d\u7cbe\u51c6\u8bc6\u522b\u4e00\u4e9b\u751a\u81f3\u662f\u5168\u90e8\u7684\u95ee\u9898<\/p>\n<h2>\u5177\u4f53\u4f7f\u7528\u8bf4\u660e<\/h2>\n<p>Valgrind\u4f1a\u8bb0\u5f55\u4e0b\u4e00\u4e9b\u6ce8\u91ca\uff0c\u6587\u672c\u6d41\uff0c\u5177\u4f53\u7684\u9519\u8bef\u62a5\u544a\u4ee5\u53ca\u5176\u4ed6\u7684\u91cd\u8981\u7684\u4e8b\u4ef6\u3002\u7c7b\u4f3c\u4e0e\u4ee5\u4e0b\u7684\u683c\u5f0f:<\/p>\n<p>==12345== some-message-from-Valgrind<\/p>\n<p><strong>12345<\/strong>\u4ee3\u8868\u8fdb\u7a0bId,\u8fd9\u4e2a\u683c\u5f0f\u65b9\u4fbf\u533a\u5206\u7a0b\u5e8f\u8f93\u51fa\u548cValgrind\u7684\u6ce8\u91ca\u8f93\u51fa\uff0c\u4ee5\u53ca\u533a\u5206\u591a\u4e2a\u8fdb\u7a0b\u7684\u8f93\u51fa\u3002Valgrind\u53ea\u4f1a\u8f93\u51fa\u6700\u91cd\u8981\u7684\u4fe1\u606f\uff0c\u5982\u679c\u9700\u8981\u4e00\u4e9b\u6b21\u8981\u7684\u4fe1\u606f\uff0c\u53ef\u4ee5\u4f7f\u7528-v\u53c2\u6570\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e09\u79cd\u65b9\u5f0f\u53bb\u5bfc\u51fa\u8fd9\u4e9b\u9519\u8bef<\/p>\n<p>1\u3001\u9ed8\u8ba4\u60c5\u51b5:\u4f1a\u76f4\u63a5\u5728\u63a7\u5236\u53f0\u6253\u5370\u51fa\u6765<br \/>\n2\u3001\u4f7f\u7528\u6587\u4ef6\u8bb0\u5f55\uff0c\u8fd9\u4e2a\u65f6\u5019\u9700\u8981\u4f7f\u7528\u53c2\u6570&#8211;log-file=filename,filename\u4ee3\u8868\u5b58\u50a8\u7684\u6587\u4ef6\u540d<br \/>\n3\u3001\u901a\u8fc7socket\u53d1\u9001:\u4f7f\u7528\u53c2\u6570&#8211;log-socket=192.168.0.1:12345\uff0c\u4e0d\u52a0\u7aef\u53e3\u53f7\u4f1a\u4f7f\u7528\u9ed8\u8ba4\u76841500\u7aef\u53e3\uff0cValgrind\u63d0\u4f9b\u4e86\u4e00\u4e2a\u53ebValgrind-listener\u7684\u5de5\u5177\u53bb\u76d1\u542c\u8fd9\u4e2a\u7f51\u7edc\u6d41\u3002<\/p>\n<h2>\u8bfb\u61c2memcheck\u5de5\u5177\u4ea7\u751f\u7684\u9519\u8bef\u4fe1\u606f<\/h2>\n<h3>1.\u975e\u6cd5\u8bfb\/\u975e\u6cd5\u5199\u7684\u9519\u8bef(Illegal read\/Illegal write errors)<\/h3>\n<p>\u4f8b\u5982:<\/p>\n<p>Invalid read of size 4<br \/>\nat 0x40F6BBCC: (within \/usr\/lib\/libpng.so.2.1.0.9)<br \/>\nby 0x40F6B804: (within \/usr\/lib\/libpng.so.2.1.0.9)<br \/>\nby 0x40B07FF4: read_png_image(QImageIO *) (kernel\/qpngio.cpp:326)<br \/>\nby 0x40AC751B: QImageIO::read() (kernel\/qimage.cpp:3621)<br \/>\nAddress 0xBFFFF0E0 is not stack&#8217;d, malloc&#8217;d or free&#8217;d<\/p>\n<p>\u51fa\u73b0\u8fd9\u4e2a\u9519\u8bef\u662f\u56e0\u4e3a\u7a0b\u5e8f\u8bfb\u6216\u5199\u4e86Valgrind\u8ba4\u4e3a\u4e0d\u5e94\u8be5\u8bfb\u5199\u7684\u5185\u5b58\u533a\u57df<\/p>\n<h3>2.\u4f7f\u7528\u4e86\u4e3a\u521d\u59cb\u5316\u7684\u503c<\/h3>\n<p>\u4f8b\u5982:<\/p>\n<p>Conditional jump or move depends on uninitialised value(s)<br \/>\nat 0x402DFA94: _IO_vfprintf (_itoa.h:49)<br \/>\nby 0x402E8476: _IO_printf (printf.c:36)<br \/>\nby 0x8048472: main (tests\/manuel1.c:8)<br \/>\n\u8fd9\u6837\u4e00\u6bb5\u9519\u8bef\u53ef\u80fd\u5c31\u662f\u7531\u4ee5\u4e0b\u7684\u4ee3\u7801\u4ea7\u751f<\/p>\n<pre><code class=\"c\">int main()\n{\nint x;\nprintf (\"x = %d\\n\", x);\n}\n<\/code><\/pre>\n<p>Valgrind\u4f1a\u8ddf\u8e2a\u53d8\u91cfx,\u76f4\u5230x\u88ab\u4f7f\u7528\u65f6\u624d\u4f1a\u62a5\u9519\u3002\u5728\u8fd9\u91ccx\u88ab\u4f20\u5165\u4e86printf,\u8fdb\u800c\u8fdb\u5165_IO_printf\uff0c\u4f46\u662f\u8fd9\u4e9b\u90fd\u4e0d\u4f1a\u62a5\u9519\uff0c\u53ea\u6709\u5f53x\u88ab\u4f20\u9012\u5230_IO_vfprintf,_IO_vfprintf\u5f00\u59cb\u68c0\u67e5x\u662f\u5426\u53ef\u4ee5\u88ab\u8f6c\u6362\u4e3aASCII\u7801\u65f6\u624d\u62a5\u9519\u3002<\/p>\n<p>\u672a\u521d\u59cb\u5316\u503c\u4e00\u822c\u6709\u4e24\u79cd\u60c5\u51b5:<\/p>\n<ul>\n<li>1\u3001\u5c40\u90e8\u53d8\u91cf\u6ca1\u6709\u88ab\u521d\u59cb\u5316\uff0c\u5c31\u50cf\u4e0a\u9762\u4e00\u6837\u3002<\/li>\n<li>2\u3001The contents of heap blocks (allocated with malloc, new, or a similar function) before you (or a constructor) write something there.<\/li>\n<\/ul>\n<p>\u4e3a\u4e86\u627e\u5230\u672a\u521d\u59cb\u5316\u53d8\u91cf\u4e00\u5f00\u59cb\u7684\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u4f7f\u7528&#8211;track-origins=yes\u53c2\u6570\u3002\u5f53\u7136\u8fd9\u4f1a\u51cf\u6162Valgrind\u7684\u4f7f\u7528\u901f\u5ea6\u3002<\/p>\n<h3>3.\u5728\u7cfb\u7edf\u8c03\u7528\u4e2d\u4f7f\u7528\u4e86\u672a\u521d\u59cb\u5316\u6216\u8005\u4e0d\u53ef\u5bfb\u5740\u7684\u503c<\/h3>\n<p>Valgrind\u4f1a\u68c0\u67e5\u6240\u6709\u7cfb\u7edf\u8c03\u7528\u7684\u53c2\u6570\uff0c\u4e00\u822c\u6709\u4ee5\u4e0b3\u7c7b:<\/p>\n<ul>\n<li>1\u3001\u68c0\u67e5\u6240\u6709\u76f4\u63a5\u8c03\u7528\u7684\u53c2\u6570\uff0c\u5373\u4f7f\u5df2\u7ecf\u521d\u59cb\u5316\u4e86\u3002<\/li>\n<li>2\u3001\u5982\u679c\u7cfb\u7edf\u8c03\u7528\u9700\u8981\u4f60\u7684\u7a0b\u5e8f\u7533\u8bf7\u7684\u7f13\u51b2\u533a\uff0cValgrind\u4f1a\u68c0\u67e5\u6240\u6709\u7684\u7f13\u51b2\u533a\u5185\u5bb9\uff0c\u770b\u5b83\u662f\u5426\u53ef\u5bfb\u5740\uff0c\u5185\u5bb9\u662f\u5426\u521d\u59cb\u5316\u4e86\u3002<\/li>\n<li>3\u3001\u5982\u679c\u7cfb\u7edf\u8c03\u7528\u9700\u8981\u5199\u5165\u7528\u6237\u63d0\u4f9b\u7684\u7f13\u51b2\uff0cValgrind\u4f1a\u68c0\u67e5\u662f\u5426\u53ef\u5bfb\u5740\u3002<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u662f\u4e24\u4e2a\u4f7f\u7528\u4e86\u65e0\u6548\u53c2\u6570\u7684\u7cfb\u7edf\u8c03\u7528\u7684\u4f8b\u5b50:<\/p>\n<pre><code class=\"c\">#include\n#include\nint main( void )\n{\nchar* arr = malloc(10);\nint* arr2 = malloc(sizeof(int));\nwrite( 1 \/* stdout *\/, arr, 10 );\nexit(arr2[0]);\n}\n<\/code><\/pre>\n<p>\u5f97\u5230\u8fd9\u6837\u7684\u9519\u8bef\u4fe1\u606f:<\/p>\n<p>Syscall param write(buf) points to uninitialised byte(s)<br \/>\nat 0x25A48723: __write_nocancel (in \/lib\/tls\/libc-2.3.3.so)<br \/>\nby 0x259AFAD3: __libc_start_main (in \/lib\/tls\/libc-2.3.3.so)<br \/>\nby 0x8048348: (within \/auto\/homes\/njn25\/grind\/head4\/a.out)<br \/>\nAddress 0x25AB8028 is 0 bytes inside a block of size 10 alloc&#8217;d<br \/>\nat 0x259852B0: malloc (vg_replace_malloc.c:130)<br \/>\nby 0x80483F1: main (a.c:5)<\/p>\n<p>Syscall param exit(error_code) contains uninitialised byte(s)<br \/>\nat 0x25A21B44: __GI__exit (in \/lib\/tls\/libc-2.3.3.so)<br \/>\nby 0x8048426: main (a.c:8)<\/p>\n<p>write\uff08a\uff09\u548cexit\uff08b\uff09\u90fd\u662f\u9519\u8bef\u7684\uff0ca\u4ece\u5806\u4e2d\u5411\u6807\u51c6\u8f93\u51fa\u4e2d\u5199\u5165\u4e86\u672a\u521d\u59cb\u5316\u7684arr\u3002b\u5411exit\u4f20\u9012\u4e86\u4e3a\u521d\u59cb\u5316\u7684\u503c\u3002\u6ce8\u610fa\u7684\u9519\u8bef\u5728\u4e8earr\u6307\u5411\u7684\u5185\u5b58\u533a\u57df\uff0c\u800cb\u7684\u9519\u8bef\u76f4\u63a5\u662farr2[0]\u3002<\/p>\n<h3>4.\u975e\u6cd5\u7684\u91ca\u653e(Illegal frees)<\/h3>\n<p>\u4f8b\u5982:<\/p>\n<p>Invalid free()<br \/>\nat 0x4004FFDF: free (vg_clientmalloc.c:577)<br \/>\nby 0x80484C7: main (tests\/doublefree.c:10)<br \/>\nAddress 0x3807F7B4 is 0 bytes inside a block of size 177 free&#8217;d<br \/>\nat 0x4004FFDF: free (vg_clientmalloc.c:577)<br \/>\nby 0x80484C7: main (tests\/doublefree.c:10)<\/p>\n<p>\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4e00\u5757\u533a\u57df\u88abfree\u4e86\u4e24\u6b21\uff0c\u6240\u4ee5\u51fa\u73b0Illegal frees\u7684\u9519\u8bef\u3002<\/p>\n<h3>5.\u4f7f\u7528\u4e0d\u5408\u9002\u7684\u91ca\u653e\u51fd\u6570\u53bb\u91ca\u653e\u5806\u533a\u57df\u7684\u5185\u5b58<\/h3>\n<p>\u4f8b\u5982:<\/p>\n<p>Mismatched free() \/ delete \/ delete []<br \/>\nat 0x40043249: free (vg_clientfuncs.c:171)<br \/>\nby 0x4102BB4E: QGArray::~QGArray(void) (tools\/qgarray.cpp:149)<br \/>\nby 0x4C261C41: PptDoc::~PptDoc(void) (include\/qmemarray.h:60)<br \/>\nby 0x4C261F0E: PptXml::~PptXml(void) (pptxml.cc:44)<br \/>\nAddress 0x4BB292A8 is 0 bytes inside a block of size 64 alloc&#8217;d<br \/>\nat 0x4004318C: operator new[](unsigned int) (vg_clientfuncs.c:152)<br \/>\nby 0x4C21BC15: KLaola::readSBStream(int) const (klaola.cc:314)<br \/>\nby 0x4C21C155: KLaola::stream(KLaola::OLENode const *) (klaola.cc:416)<br \/>\nby 0x4C21788F: OLEFilter::convert(QCString const &amp;) (olefilter.cc:272)<\/p>\n<p>\u8fd9\u4e2a\u9519\u8bef\u662f\u56e0\u4e3a\u4f7f\u7528new[]\u5f00\u8f9f\u5185\u5b58\u7a7a\u95f4\uff0c\u5374\u4f7f\u7528\u4e86free\u53bb\u91ca\u653e\u5185\u5b58\u3002<br \/>\n\u4f7f\u7528malloc, calloc, realloc, valloc or memalign,\u5fc5\u987b\u4f7f\u7528free\u91ca\u653e\u5185\u5b58\u3002<br \/>\n\u4f7f\u7528new, \u5fc5\u987b\u4f7f\u7528delete\u91ca\u653e\u5185\u5b58\u3002<br \/>\n\u4f7f\u7528new[],\u5fc5\u987b\u4f7f\u7528delete[]\u91ca\u653e\u5185\u5b58\u3002<\/p>\n<h3>6.\u6e90\u5185\u5b58\u533a\u57df\u548c\u76ee\u6807\u5185\u5b58\u533a\u57df\u91cd\u53e0<\/h3>\n<p>memcpy, strcpy, strncpy, strcat, strncat\u8fd9\u4e9b\u51fd\u6570\u53ef\u4ee5\u4ece\u6e90\u5185\u5b58\u533a\u57df\u590d\u5236\u5185\u5bb9\u5230\u76ee\u6807\u5185\u5b58\u533a\u57df\u3002\u8fd9\u4e24\u5757\u533a\u57df\u662f\u4e0d\u53ef\u4ee5\u91cd\u53e0\u7684\u3002POSIX\u6807\u51c6\u89c4\u5b9a\u8fd9\u79cd\u884c\u4e3a\u662f\u672a\u5b9a\u4e49\u7684\u3002<br \/>\n\u4f8b\u5982<\/p>\n<p>==27492== Source and destination overlap in memcpy(0xbffff294, 0xbffff280, 21)<br \/>\n==27492== at 0x40026CDC: memcpy (mc_replace_strmem.c:71)<br \/>\n==27492== by 0x804865A: main (overlap.c:40)<\/p>\n<h3>7.Fishy argument values<\/h3>\n<p>\u6240\u4ee5\u7684\u5185\u5b58\u5206\u914d\u51fd\u6570\u90fd\u6307\u5b9a\u4e86\u5206\u914d\u7684\u5185\u5b58\u5927\u5c0f\uff0c\u8fd9\u4e2a\u5927\u5c0f\u5fc5\u5b9a\u4e3a\u6b63\u6570\uff0c\u6216\u8005\u4e00\u822c\u60c5\u51b5\u4e0b\u4e0d\u4f1a\u6781\u5ea6\u7684\u5927\u3002\u4f8b\u5982\u572864\u4f4d\u7684\u673a\u5668\u4e0a\uff0c\u4e0d\u4f1a\u7533\u8bf7\u5206\u914d2^63\u5927\u5c0f\u7684\u5185\u5b58\u3002\u8fd9\u79cd\u4e3a\u8d1f\u6570\u7684\u6216\u8005\u8fc7\u4e8e\u5927\u7684\u53c2\u6570\u88ab\u6210\u4e3aFishy argument\u3002<br \/>\n\u4f8b\u5982:<\/p>\n<p>==32233== Argument &#8216;size&#8217; of function malloc has a fishy (possibly negative) value: -3<br \/>\n==32233== at 0x4C2CFA7: malloc (vg_replace_malloc.c:298)<br \/>\n==32233== by 0x400555: foo (fishy.c:15)<br \/>\n==32233== by 0x400583: main (fishy.c:23)<\/p>\n<h3>8.\u5185\u5b58\u6cc4\u6f0f\u68c0\u6d4b<\/h3>\n<p>Valgrind\u4f1a\u8ddf\u8e2a\u6240\u6709\u7531malloc\u6216new\u7533\u8bf7\u7684\u5185\u5b58\uff0c\u6240\u4ee5\u5f53\u7a0b\u5e8f\u9000\u51fa\u65f6,Valgrind\u77e5\u9053\u54ea\u4e9b\u5185\u5b58\u6ca1\u6709\u88ab\u4e3b\u52a8\u91ca\u653e\u3002<br \/>\n\u5982\u679c&#8211;leak-check\u53c2\u6570\u8bbe\u7f6e\u5f97\u5f53\uff0c\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u672a\u88ab\u91ca\u653e\u7684\u5185\u5b58\u5757\uff0cValgrind\u5224\u65ad\u4eceroot-set\u4e2d\u7684\u6307\u9488\u662f\u5426\u80fd\u5230\u8fbe\u8fd9\u4e9b\u5185\u5b58\u5757\u3002root-set\u5305\u542b\uff08a\uff09\u666e\u901a\u7684\u6240\u6709\u7ebf\u7a0b\u4f7f\u7528\u7684\u5bc4\u5b58\u5668\uff0c\uff08b\uff09\u521d\u59cb\u5316\u7684, \u5bf9\u9f50\u7684, \u6307\u9488\u5927\u5c0f\u7684\u6570\u636e\u5757\uff0c\u5305\u62ec\u6808\u3002\u4e00\u4e2a\u6570\u636e\u5757\u6709\u4e24\u79cd\u65b9\u5f0f\u53ef\u5230\u8fbe\uff0c\u7b2c\u4e00\u79cd\u662f\u201cstart-pointer\u201d\uff0c\u5373\u6307\u9488\u5728\u6570\u636e\u5757\u7684\u5f00\u5934;\u7b2c\u4e8c\u79cd\u662f\u201cinterior-pointer\u201d\uff0c\u5373\u6307\u9488\u5728\u6570\u636e\u5757\u7684\u4e2d\u95f4\u3002\u201cinterior-pointer\u201d\u6709\u591a\u79cd\u65b9\u5f0f\u51fa\u73b0\uff1a<\/p>\n<ul>\n<li>\u6307\u9488\u4e00\u5f00\u59cb\u662f\u201cstart-pointer\u201d\uff0c\u88ab\u7a0b\u5e8f\u6709\u610f\u6216\u65e0\u610f\u7684\u79fb\u52a8\u5230\u4e2d\u95f4\u3002<\/p>\n<\/li>\n<li>\n<p>\u53ef\u80fd\u53ea\u662f\u5de7\u5408\u3002<\/p>\n<\/li>\n<li>\n<p>std::string\u4e2d\u7684char\u7684\u6307\u9488\u3002<\/p>\n<\/li>\n<li>\n<p>\u6709\u4e9b\u4ee3\u7801\u5206\u914d\u5757\u5185\u5b58\uff0c\u4f7f\u7528\u524d8\u4e2a\u53bb\u5b58\u50a8\u4f5c\u4e3a64\u4f4d\u7684\u6570\u3002\u4f8b\u5982sqlite3MemMalloc\u5c31\u662f\u8fd9\u6837\u505a\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>\u53ef\u80fd\u662f\u4e00\u4e2ac++\u5bf9\u8c61\uff08\u5177\u6709\u6790\u6784\u51fd\u6570\uff09\u6570\u7ec4\u7684\u6307\u9488\uff0c\u7531new[]\u6765\u5206\u914d\u5185\u5b58\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6709\u4e9b\u7f16\u8bd1\u5668\u5b58\u50a8\u4e00\u4e2a\u201cmagic cookie\u201d\uff0c\u5305\u542b\u6570\u7ec4\u957f\u5ea6\u5b58\u50a8\u5728\u5206\u914d\u7684\u5757\u5f00\u5934\u3002<\/p>\n<\/li>\n<li>\n<p>\u53ef\u80fd\u662f\u4e00\u4e2a\u591a\u91cd\u7ee7\u627f\u4ea7\u751f\u7684c++\u5bf9\u8c61\u7684\u5185\u90e8\u90e8\u5206\u7684\u6307\u9488\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5728\u4f7f\u7528\u4e86\u542f\u53d1\u5f0f\uff08heuristics\uff09\u7684\u60c5\u51b5\u4e0b\uff0cstdstring, length64, newarray and multipleinheritance\u60c5\u51b5\u4e0b\u7684\u201cinterior-pointer\u201d\u4f1a\u88ab\u5f53\u6210\u201cstart-pointer\u201d\u5bf9\u5f85\u3002<\/p>\n<p>\u8003\u8651\u4e0b\u9762\u8fd9\u4e5d\u79cd\u60c5\u51b5\uff1a<\/p>\n<p>Pointer chain AAA Leak Case BBB Leak Case<\/p>\n<hr \/>\n<p>(1) RRR &#8212;&#8212;&#8212;&#8212;&gt; BBB DR<br \/>\n(2) RRR &#8212;&gt; AAA &#8212;&gt; BBB DR IR<br \/>\n(3) RRR BBB DL<br \/>\n(4) RRR AAA &#8212;&gt; BBB DL IL<br \/>\n(5) RRR &#8212;&#8212;?&#8212;&#8211;&gt; BBB (y)DR, (n)DL<br \/>\n(6) RRR &#8212;&gt; AAA -?-&gt; BBB DR (y)IR, (n)DL<br \/>\n(7) RRR -?-&gt; AAA &#8212;&gt; BBB (y)DR, (n)DL (y)IR, (n)IL<br \/>\n(8) RRR -?-&gt; AAA -?-&gt; BBB (y)DR, (n)DL (y,y)IR, (n,y)IL, (_,n)DL<br \/>\n(9) RRR AAA -?-&gt; BBB DL (y)IL, (n)DL<\/p>\n<p>Pointer chain legend:<br \/>\n&#8211; RRR: a root set node or DR block(\u4e00\u4e2aroot set\u6216\u8005\u76f4\u63a5\u53ef\u8fbe\u7684\u5757\uff09<br \/>\n&#8211; AAA, BBB: heap blocks\uff08\u5806\u5757\uff09<br \/>\n&#8211; &#8212;&gt;: a start-pointer \uff08\u5934\u6307\u9488\uff09<br \/>\n&#8211; -?-&gt;: an interior-pointer \uff08\u5185\u90e8\u6307\u9488\uff09<\/p>\n<p>Leak Case legend:<br \/>\n&#8211; DR: Directly reachable \uff08\u76f4\u63a5\u53ef\u8fbe\uff09<br \/>\n&#8211; IR: Indirectly reachable \uff08\u4e0d\u76f4\u63a5\u53ef\u8fbe\uff09<br \/>\n&#8211; DL: Directly lost \uff08\u76f4\u63a5\u4e22\u5931\uff09<br \/>\n&#8211; IL: Indirectly lost \uff08\u4e0d\u76f4\u63a5\u4e22\u5931\uff09<br \/>\n&#8211; (y)XY: it&#8217;s XY if the interior-pointer is a real pointer \uff08\u5185\u90e8\u6307\u9488\u662f\u4e00\u4e2a\u771f\u5b9e\u7684\u6307\u9488\uff09<br \/>\n&#8211; (n)XY: it&#8217;s XY if the interior-pointer is not a real pointer \uff08\u5185\u90e8\u6307\u9488\u4e0d\u662f\u4e00\u4e2a\u771f\u5b9e\u7684\u6307\u9488\uff09<br \/>\n&#8211; (_)XY: it&#8217;s XY in either case \uff08\u4efb\u610f\u4e00\u4e2a\u60c5\u51b5\uff09<\/p>\n<p>\u4efb\u610f\u4e00\u79cd\u60c5\u51b5\u90fd\u53ef\u4ee5\u88ab\u5f52\u4e3a\u4e0a\u8ff09\u79cd\u60c5\u51b5\u4e4b\u4e00\uff0cValgrind\u5408\u5e76\u5176\u4e2d\u4e00\u4e9b\u60c5\u51b5\uff0c\u5f97\u51fa4\u79cd\u53ef\u80fd<\/p>\n<ul>\n<li>&#8220;Still reachable\uff08\u4f9d\u7136\u53ef\u8fbe\uff09&#8221;\u3002 \u8fd9\u5305\u542b\u60c5\u51b5 1 \u548c 2 (for the BBB blocks) \u3002 \u4e00\u4e2a\u5185\u5b58\u5757\u7684\u5934\u6307\u9488\u7684\u6216\u8005\u5934\u6307\u9488\u7684\u94fe\u88ab\u53d1\u73b0\uff0c\u7a0b\u5e8f\u5458\u81f3\u5c11\u5728\u539f\u7406\u4e0a\u91ca\u653e\u4e86\u8fd9\u5757\u5185\u5b58\u5728\u7a0b\u5e8f\u9000\u51fa\u4e4b\u524d\u3002\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u666e\u904d\u5e76\u4e14\u4e0d\u7b97\u662f\u4e00\u4e2a\u95ee\u9898\uff0cValgrind\u9ed8\u8ba4\u4e0d\u62a5\u544a\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<\/li>\n<li>\n<p>&#8220;Definitely lost\uff08\u7edd\u5bf9\u4e22\u5931\uff09&#8221;\u3002 \u8fd9\u5305\u542b\u60c5\u51b53 (for the BBB blocks) \u3002\u8fd9\u610f\u5473\u7740\u8fd9\u4e2a\u6570\u636e\u5757\u6ca1\u6709\u6307\u9488\u53ef\u8fbe\u3002\u6570\u636e\u5757\u88ab\u5f52\u4e3a\u4e22\u5931\uff0c\u56e0\u4e3a\u7a0b\u5e8f\u5458\u5728\u7a0b\u5e8f\u7ed3\u675f\u65f6\u4e0d\u80fd\u4e3b\u52a8\u91ca\u653e\u5b83\uff0c\u539f\u56e0\u662f\u6ca1\u6709\u6307\u9488\u6307\u5411\u8fd9\u5757\u5185\u5b58\u3002 \u8fd9\u53ef\u80fd\u662f\u5728\u8f83\u65e9\u4e4b\u524d\u4e22\u5931\u4e86\u6307\u5411\u5185\u5b58\u533a\u57df\u7684\u6307\u9488\u3002<\/p>\n<\/li>\n<li>\n<p>&#8220;Indirectly lost\uff08\u975e\u76f4\u63a5\u4e22\u5931\uff09&#8221;\u3002\u8fd9\u5305\u542b\u60c5\u51b54\u548c9 (for the BBB blocks)\u3002\u8fd9\u610f\u5473\u7740\u6570\u636e\u5757\u4e22\u5931\u4e0d\u662f\u56e0\u4e3a\u6ca1\u6709\u6307\u9488\u6307\u5411\u5b83\uff0c\u800c\u662f\u56e0\u4e3a\u6240\u6709\u7684\u6307\u5411\u6570\u636e\u5757\u7684\u6307\u9488\u81ea\u5df1\u4e22\u5931\u4e86\u3002 \u4e3e\u4f8b\u6765\u8bf4\uff0c\u5982\u679c\u4f60\u6709\u4e00\u4e2a\u4e8c\u53c9\u6811\uff0c\u6839\u8282\u70b9\u4e22\u5931\uff0c\u6240\u6709\u7684\u4ed6\u7684\u5b50\u8282\u70b9\u90fd\u53d8\u6210\u975e\u76f4\u63a5\u4e22\u5931\u3002\u56e0\u4e3a\u6839\u8282\u70b9\u7684\u76f4\u63a5\u4e22\u5931\u95ee\u9898\u88ab\u89e3\u51b3\uff0c\u5b50\u8282\u70b9\u7684\u975e\u76f4\u63a5\u4e22\u5931\u95ee\u5c31\u4f1a\u6d88\u5931\u3002Valgrind\u9ed8\u8ba4\u4e0d\u62a5\u544a\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<\/li>\n<li>\n<p>&#8220;Possibly lost\uff08\u53ef\u80fd\u4e22\u5931\uff09&#8221;\u3002 \u8fd9\u5305\u542b\u60c5\u51b55\u30016\u30017\u30018 (for the BBB blocks) \u3002 \u8fd9\u610f\u5473\u7740\u4e00\u4e2a\u6216\u591a\u4e2a\u6570\u636e\u5757\u6307\u9488\u88ab\u53d1\u73b0\uff0c\u4f46\u662f\u81f3\u5c11\u4e00\u4e2a\u6307\u9488\u662f\u5185\u90e8\u6307\u9488\u3002\u8fd9\u53ef\u80fd\u53ea\u662f\u4e00\u4e2a\u5185\u5b58\u4e2d\u7684\u968f\u673a\u503c\uff0c\u521a\u597d\u6307\u5411\u4e00\u4e2a\u6570\u636e\u5757\uff0c\u6240\u4ee5\u4f60\u4e0d\u9700\u8981\u8003\u8651\u8fd9\u4e2a\u60c5\u51b5\u9664\u975e\u4f60\u77e5\u9053\u4f60\u7684\u4ee3\u7801\u4e2d\u51fa\u73b0\u4e86\u5185\u90e8\u6307\u9488\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u5185\u5b58\u6cc4\u6f0f\u7684\u603b\u7ed3\u7684\u4f8b\u5b50<\/p>\n<p>LEAK SUMMARY:<br \/>\ndefinitely lost: 48 bytes in 3 blocks.<br \/>\nindirectly lost: 32 bytes in 2 blocks.<br \/>\npossibly lost: 96 bytes in 6 blocks.<br \/>\nstill reachable: 64 bytes in 4 blocks.<br \/>\nsuppressed: 0 bytes in 0 blocks.<\/p>\n<p>\u5982\u679c\u5f00\u542f\u7684\u542f\u53d1\u5f0f\u7684\u9009\u9879\uff0c\u7c7b\u4f3c\u4e8e\u4ee5\u4e0b\u8f93\u51fa<\/p>\n<p>LEAK SUMMARY:<br \/>\ndefinitely lost: 4 bytes in 1 blocks<br \/>\nindirectly lost: 0 bytes in 0 blocks<br \/>\npossibly lost: 0 bytes in 0 blocks<br \/>\nstill reachable: 95 bytes in 6 blocks<br \/>\nof which reachable via heuristic:<br \/>\nstdstring : 56 bytes in 2 blocks<br \/>\nlength64 : 16 bytes in 1 blocks<br \/>\nnewarray : 7 bytes in 1 blocks<br \/>\nmultipleinheritance: 8 bytes in 1 blocks<br \/>\nsuppressed: 0 bytes in 0 blocks<\/p>\n<p>\u5982\u679c &#8211;leak-check=full \u88ab\u6307\u5b9a, Memcheck \u4f1a\u7ed9\u51fa\u6bcf\u4e00\u4e2a\u7edd\u5bf9\u4e22\u5931\u6216\u53ef\u80fd\u4e22\u5931\u5757\u7684\u8be6\u7ec6\u60c5\u51b5\uff0c\u5305\u62ec\u4ed6\u4eec\u5728\u54ea\u91cc\u88ab\u5206\u914d\u3002\u5b83\u4e0d\u80fd\u544a\u8bc9\u4f60\u4f55\u65f6\u3001\u5982\u4f55\u3001\u4e3a\u4f55\u6307\u5411\u4e00\u4e2a\u6cc4\u9732\u5185\u5b58\u5757\u7684\u6307\u9488\u4e22\u5931\u4e86;\u8fd9\u4e2a\u9700\u8981\u81ea\u5df1\u89e3\u51b3\u3002\u901a\u5e38\uff0c\u4f60\u9700\u8981\u4fdd\u8bc1\u5728\u7a0b\u5e8f\u9000\u51fa\u65f6\uff0c\u4f60\u7684\u7a0b\u5e8f\u6ca1\u6709\u4efb\u4f55\u7684\u7edd\u5bf9\u4e22\u5931\u6216\u8005\u53ef\u80fd\u4e22\u5931\u7684\u5185\u5b58\u5757\u3002<\/p>\n<p>\u4f8b\u5982<\/p>\n<p>8 bytes in 1 blocks are definitely lost in loss record 1 of 14<br \/>\nat 0x&#8230;&#8230;..: malloc (vg_replace_malloc.c:&#8230;)<br \/>\nby 0x&#8230;&#8230;..: mk (leak-tree.c:11)<br \/>\nby 0x&#8230;&#8230;..: main (leak-tree.c:39)<\/p>\n<p>88 (8 direct, 80 indirect) bytes in 1 blocks are definitely lost in loss record 13 of 14<br \/>\nat 0x&#8230;&#8230;..: malloc (vg_replace_malloc.c:&#8230;)<br \/>\nby 0x&#8230;&#8230;..: mk (leak-tree.c:11)<br \/>\nby 0x&#8230;&#8230;..: main (leak-tree.c:25)<\/p>\n<p>\u7b2c\u4e00\u6761\u4fe1\u606f\u63cf\u8ff0\u4e86\u4e00\u79cd\u7b80\u5355\u7684\u60c5\u51b5\uff0c\u4e00\u4e2a8byte\u7684\u5185\u5b58\u5757\u7edd\u5bf9\u4e22\u5931\u4e86\u3002\u7b2c\u4e8c\u79cd\u60c5\u51b5\u63cf\u8ff0\u4e86\u53e6\u5916\u4e00\u4e2a8byte\u5185\u5b58\u5757\u7edd\u5bf9\u4e22\u5931;\u4e0d\u540c\u5728\u4e8e\u7b2c\u4e8c\u79cd\u60c5\u51b5\u4f1a\u5f15\u8d77\u5728\u53e6\u5916\u5185\u5b58\u5757\u4e2d\u7684\u66f4\u591a\u768480bytes\u5185\u5b58\u975e\u76f4\u63a5\u4e22\u5931\u4e86\u3002loss number\u6ca1\u6709\u4efb\u4f55\u7279\u6b8a\u7684\u542b\u4e49\u3002\u8fd9\u4e2aloss number\u53ef\u4ee5\u5728Valgrind gdbserver\u4e2d\u7528\u6765\u5217\u51fa\u6cc4\u6f0f\u5185\u5b58\u5757\u7684\u5730\u5740\uff0c\u6216\u8005\u7ed9\u51fa\u66f4\u591a\u7684\u4fe1\u606f\u5173\u4e8e\u4e3a\u4f55\u4e00\u4e2a\u5185\u5b58\u5757\u4ecd\u7136\u53ef\u8fbe\u3002<\/p>\n<p>\u5f53 &#8211;leak-check=full \u88ab\u6307\u5b9a\u65f6\uff0c\u9009\u9879&#8211;show-leak-kinds= \u63a7\u5236\u663e\u793a\u7684\u6cc4\u6f0f\u7c7b\u578b\u3002<\/p>\n<p>\u6709\u4e0b\u9762\u51e0\u79cd\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li>\u5355\u72ec\u6307\u5b9a\u4e00\u6216\u591a\u4e2a\uff1a definite indirect possible reachable\u3002<\/li>\n<li>all\u4ee3\u8868\u6240\u6709\u3002<\/li>\n<li>none \u4ee3\u8868\u7a7a\u96c6\u5408\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\u4f7f\u7528 &#8211;show-leak-kinds=definite,possible \u6765\u53ea\u663e\u793a\u7edd\u5bf9\u6216\u8005\u53ef\u80fd\u7684\u5185\u5b58\u4e22\u5931\u3002<\/p>\n<h2>\u6ce8\u610f\u4e8b\u9879<\/h2>\n<p>\u5728\u8c03\u8bd5php\u65f6,\u56e0\u4e3aphp\u81ea\u5df1\u5b9e\u73b0\u4e86\u5185\u5b58\u7ba1\u7406\u673a\u5236,\u6240\u6709\u4f7f\u7528valgrind\u65f6,\u4f1a\u68c0\u6d4b\u51fa\u5f88\u591aphp\u4e0a\u7684\u5185\u5b58\u6cc4\u9732,\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7<code>export USE_ZEND_ALLOC=0<\/code>\u6765\u8ba9php\u76f4\u63a5\u5411\u5185\u5b58\u7533\u8bf7\u5185\u5b58,\u8fd9\u6837\u6709\u52a9\u4e8e\u53d1\u73b0\u95ee\u9898<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528valgrind\u8fdb\u884c\u5185\u5b58\u5206\u6790 \u7b80\u4ecb \u5b98\u7f51\u5730\u5740:http:\/\/valgrind.org \u4e3b\u8981\u63d0\u4f9b\u4ee5\u4e0b\u5de5\u5177\uff1a  &hellip; <a href=\"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">linux\u4e0bc\/c++\u7684\u5185\u5b58\u6cc4\u6f0f\u5206\u6790<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[],"class_list":["post-14","post","type-post","status-publish","format-standard","hentry","category-cplusplus","category-linux"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>linux\u4e0bc\/c++\u7684\u5185\u5b58\u6cc4\u6f0f\u5206\u6790 - \u4e00\u53ea\u5b89\u9759\u7684\u732b<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"linux\u4e0bc\/c++\u7684\u5185\u5b58\u6cc4\u6f0f\u5206\u6790 - \u4e00\u53ea\u5b89\u9759\u7684\u732b\" \/>\n<meta property=\"og:description\" content=\"\u4f7f\u7528valgrind\u8fdb\u884c\u5185\u5b58\u5206\u6790 \u7b80\u4ecb \u5b98\u7f51\u5730\u5740:http:\/\/valgrind.org \u4e3b\u8981\u63d0\u4f9b\u4ee5\u4e0b\u5de5\u5177\uff1a &hellip; \u7ee7\u7eed\u9605\u8bfblinux\u4e0bc\/c++\u7684\u5185\u5b58\u6cc4\u6f0f\u5206\u6790\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/\" \/>\n<meta property=\"og:site_name\" content=\"\u4e00\u53ea\u5b89\u9759\u7684\u732b\" \/>\n<meta property=\"article:published_time\" content=\"2017-04-19T09:25:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-06-26T04:35:33+00:00\" \/>\n<meta name=\"author\" content=\"jiangpengfei\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"jiangpengfei\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/\"},\"author\":{\"name\":\"jiangpengfei\",\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685\"},\"headline\":\"linux\u4e0bc\/c++\u7684\u5185\u5b58\u6cc4\u6f0f\u5206\u6790\",\"datePublished\":\"2017-04-19T09:25:30+00:00\",\"dateModified\":\"2018-06-26T04:35:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/\"},\"wordCount\":922,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685\"},\"articleSection\":[\"c++\",\"linux\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/\",\"url\":\"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/\",\"name\":\"linux\u4e0bc\/c++\u7684\u5185\u5b58\u6cc4\u6f0f\u5206\u6790 - \u4e00\u53ea\u5b89\u9759\u7684\u732b\",\"isPartOf\":{\"@id\":\"https:\/\/www.myway5.com\/#website\"},\"datePublished\":\"2017-04-19T09:25:30+00:00\",\"dateModified\":\"2018-06-26T04:35:33+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.myway5.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"linux\u4e0bc\/c++\u7684\u5185\u5b58\u6cc4\u6f0f\u5206\u6790\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.myway5.com\/#website\",\"url\":\"https:\/\/www.myway5.com\/\",\"name\":\"\u4e00\u53ea\u5b89\u9759\u7684\u732b\",\"description\":\"\u60f3\u5565\u5462\",\"publisher\":{\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.myway5.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685\",\"name\":\"jiangpengfei\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f8c7de757f6e0247412bcfd31b7c2271?s=96&d=monsterid&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f8c7de757f6e0247412bcfd31b7c2271?s=96&d=monsterid&r=g\",\"caption\":\"jiangpengfei\"},\"logo\":{\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.myway5.com\/index.php\/author\/joyme\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"linux\u4e0bc\/c++\u7684\u5185\u5b58\u6cc4\u6f0f\u5206\u6790 - \u4e00\u53ea\u5b89\u9759\u7684\u732b","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/","og_locale":"zh_CN","og_type":"article","og_title":"linux\u4e0bc\/c++\u7684\u5185\u5b58\u6cc4\u6f0f\u5206\u6790 - \u4e00\u53ea\u5b89\u9759\u7684\u732b","og_description":"\u4f7f\u7528valgrind\u8fdb\u884c\u5185\u5b58\u5206\u6790 \u7b80\u4ecb \u5b98\u7f51\u5730\u5740:http:\/\/valgrind.org \u4e3b\u8981\u63d0\u4f9b\u4ee5\u4e0b\u5de5\u5177\uff1a &hellip; \u7ee7\u7eed\u9605\u8bfblinux\u4e0bc\/c++\u7684\u5185\u5b58\u6cc4\u6f0f\u5206\u6790","og_url":"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/","og_site_name":"\u4e00\u53ea\u5b89\u9759\u7684\u732b","article_published_time":"2017-04-19T09:25:30+00:00","article_modified_time":"2018-06-26T04:35:33+00:00","author":"jiangpengfei","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"jiangpengfei","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/#article","isPartOf":{"@id":"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/"},"author":{"name":"jiangpengfei","@id":"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685"},"headline":"linux\u4e0bc\/c++\u7684\u5185\u5b58\u6cc4\u6f0f\u5206\u6790","datePublished":"2017-04-19T09:25:30+00:00","dateModified":"2018-06-26T04:35:33+00:00","mainEntityOfPage":{"@id":"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/"},"wordCount":922,"commentCount":0,"publisher":{"@id":"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685"},"articleSection":["c++","linux"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/","url":"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/","name":"linux\u4e0bc\/c++\u7684\u5185\u5b58\u6cc4\u6f0f\u5206\u6790 - \u4e00\u53ea\u5b89\u9759\u7684\u732b","isPartOf":{"@id":"https:\/\/www.myway5.com\/#website"},"datePublished":"2017-04-19T09:25:30+00:00","dateModified":"2018-06-26T04:35:33+00:00","breadcrumb":{"@id":"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.myway5.com\/index.php\/2017\/04\/19\/linux-c-or-c-plus-plus-memory-leak-analysis\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.myway5.com\/"},{"@type":"ListItem","position":2,"name":"linux\u4e0bc\/c++\u7684\u5185\u5b58\u6cc4\u6f0f\u5206\u6790"}]},{"@type":"WebSite","@id":"https:\/\/www.myway5.com\/#website","url":"https:\/\/www.myway5.com\/","name":"\u4e00\u53ea\u5b89\u9759\u7684\u732b","description":"\u60f3\u5565\u5462","publisher":{"@id":"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.myway5.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685","name":"jiangpengfei","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.myway5.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f8c7de757f6e0247412bcfd31b7c2271?s=96&d=monsterid&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f8c7de757f6e0247412bcfd31b7c2271?s=96&d=monsterid&r=g","caption":"jiangpengfei"},"logo":{"@id":"https:\/\/www.myway5.com\/#\/schema\/person\/image\/"},"url":"https:\/\/www.myway5.com\/index.php\/author\/joyme\/"}]}},"views":3911,"_links":{"self":[{"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/posts\/14","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/comments?post=14"}],"version-history":[{"count":4,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/posts\/14\/revisions"}],"predecessor-version":[{"id":324,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/posts\/14\/revisions\/324"}],"wp:attachment":[{"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/media?parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/categories?post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/tags?post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}