GDB调试之内存泄漏检测(二十二)
内存泄漏检测常用命令:
- call malloc_stats()
- call malloc_info(0, stdout)
调试代码如下所示:
#include <malloc.h>
#include <string.h>
#include <thread>
#include <iostream>
#include <vector>
#include <string>
#include <assert.h>
using namespace std;
void test_malloc_leak(int size)
{
malloc(1024);
}
void no_leak()
{
void *p=malloc(1024*1024*10);
free(p);
}
int main(int argc,char* argv[])
{
no_leak();
test_malloc_leak(1024);
return 0;
}
call malloc_stats()的使用:


call malloc_info(0, stdout)函数的使用:
