C 記憶體洩露檢測

2021-07-06 07:14:30 字數 817 閱讀 8021

記憶體檢測相關命令:

valgrind –tool=memcheck –leak-check=full –undef-value-errors=yes ./ql_circle_svr2 -id 20000 -tcp 192.168.1.55:8000 -svr 192.168.1.55:8015

valgrind –tool=memcheck –leak-check=full –undef-value-errors=yes ./ql_connect_svr2 -id 30000 -tcp 192.168.1.55:8100 -svr 192.168.1.55:8015

valgrind –tool=memcheck –leak-check=full –undef-value-errors=yes ./ql_data_center2 -id 10000 -tcp 192.168.1.55:8015

valgrind –tool=memcheck –leak-check=full –undef-value-errors=yes ./ql_storage_svr -id 40000 -tcp 192.168.1.55:8300 -svr 192.168.1.55:8015

1、常見記憶體洩露情況:

(1)動態記憶體洩露:呼叫了malloc/new等記憶體申請的操作,但缺少了對應的free/delete;

(2)資源洩露:檔案開啟後未關閉;

(3)動態記憶體越界:

static void mem_overrun1(void)

(5)動態記憶體兩次 free;

(6)使用野指標,即未初始化的指標;

(7)釋放野指標,即未初始化的指標;

C 檢測記憶體洩露

p new int p指標修改,原來申請記憶體的位址沒有記錄下來,於是無法釋放 下面介紹如何檢查記憶體洩漏 1.包含標頭檔案和定義 define crtdbg map alloc 並非絕對需要該語句,但如果有該語句,列印出來的是檔名和行數等更加直觀的資訊 include include 1 incl...

c 記憶體洩露檢測

當我們進行c 程式設計的時候經常遇到的乙個問題是記憶體洩露,尤其在進行乙個大型的專案的時候,可能會用到幾十個類,稍加不小心造成記憶體洩露,一般常用以下兩種方法 方法一 ifdef debug define new new normal block,file line endif define crt...

c 記憶體洩露檢測

vs平台下提供了crt庫檢測和識別記憶體洩漏的有效方法。原理大致如下 記憶體分配要通過crt在執行時實現,只要在分配記憶體和釋放記憶體時分別做好記錄,程式結束時對比分配記憶體和釋放記憶體的記錄就可以確定是不是有記憶體洩漏。1.在vs中使用時,需加上 define crtdbg map alloc i...