亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1169 | 回復(fù): 0
打印 上一主題 下一主題

Valgrind初探 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2009-11-19 12:48 |只看該作者 |倒序瀏覽
  今天調(diào)試一段代碼的時候,無意間發(fā)現(xiàn)內(nèi)存泄漏,top命令查看到的進(jìn)程內(nèi)存持續(xù)增長。檢查了半天的malloc和free,實(shí)在是沒有找到問題。沒辦法,在網(wǎng)上查看了寫帖子,知道有Valgrind這個東東,于是下下來,試了下,結(jié)果,就執(zhí)行了一次便發(fā)現(xiàn)了程序的問題:
  使用參數(shù)valgrind --tool=memcheck --leak-check=yes ./hsvr_smp,
==16790==
==16790== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 16 from 2)
==16790== malloc/free: in use at exit: 1003488 bytes in 241 blocks.
==16790== malloc/free: 333 allocs, 92 frees, 1366168 bytes allocated.
==16790== For counts of detected errors, rerun with: -v
==16790== searching for pointers to 241 not-freed blocks.
==16790== checked 10218852 bytes.
==16790==
==16790== 3872 bytes in 44 blocks are possibly lost in loss record 18 of 21
==16790== at 0x1B904984: malloc (vg_replace_malloc.c:131)
==16790== by 0x80527C4: my_malloc (in /home/nari/exe/hsvr_smp3)
==16790== by 0x80686C1: mysql_store_result (in /home/nari/exe/hsvr_smp)
==16790== by 0x804B173: HDBChecktbl (hmysql.c:398)
==16790==
==16790== LEAK SUMMARY:
==16790== definitely lost: 0 bytes in 0 blocks.
==16790== possibly lost: 3872 bytes in 44 blocks.
==16790== still reachable: 999616 bytes in 197 blocks.
==16790== suppressed: 0 bytes in 0 blocks.
==16790== Reachable blocks (those to which a pointer was found) are not shown.
==16790== To see them, rerun with: --show-reachable=yes
   
  看到上面提示的函數(shù)棧,找到HDBChecktbl 函數(shù)內(nèi)的 mysql_store_result 函數(shù),原來
這段代碼中調(diào)用了mysql_store_result卻沒有調(diào)用mysql_free_result。難怪自己沒有找到malloc和free方面的錯誤。
  修改相關(guān)程序再執(zhí)行 ,得到下面的結(jié)果:
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 16 from 2)
==16892== malloc/free: in use at exit: 278896 bytes in 65 blocks.
==16892== malloc/free: 165 allocs, 100 frees, 675016 bytes allocated.
==16892== For counts of detected errors, rerun with: -v
==16892== searching for pointers to 65 not-freed blocks.
==16892== checked 10203892 bytes.
==16892==
==16892== LEAK SUMMARY:
==16892== definitely lost: 0 bytes in 0 blocks.
==16892== possibly lost: 0 bytes in 0 blocks.
==16892== still reachable: 278896 bytes in 65 blocks.
==16892== suppressed: 0 bytes in 0 blocks.
==16892== Reachable blocks (those to which a pointer was found) are not shown.
==16892== To see them, rerun with: --show-reachable=yes
     由此看到,valgrind 可以很方便的指導(dǎo)程序員找到錯誤的地方。

本文來自ChinaUnix博客,如果查看原文請點(diǎn):http://blog.chinaunix.net/u2/87101/showart_2098251.html
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP